ATLTangram Attributes Sample: Demonstrates Managing Large Projects That Use ATL, MFC, and COM

ATLTangram is a port of the Tangram example found in the last chapter of Dale Rogerson's Inside COM (https://mspress.microsoft.com). Many thanks to Dale for doing all the hard work and allowing us to use the code in an ATL sample. This sample will help you convert a legacy COM application to one that uses ATL for its infrastructure.

ATLTangram is a large project consisting of the ATLTangram solution, which is the master controller for six subprojects: MFCTangram, ATLModel, ATLGdiWorld, ATLGLWorld, ATLModelExe, and ATLTangramCanvas. The sample demonstrates several features of the integrated development environment (IDE) and several COM concepts. The sample also demonstrates using MFC as the client of ATL COM servers.

Security noteSecurity Note

This sample code is intended to illustrate a concept, and it shows only the code that is relevant to that concept. It may not meet the security requirements for a specific environment, and it should not be used exactly as shown. We recommend that you add security and error-handling code to make your projects more secure and robust. Microsoft provides this sample code "AS IS" with no warranties.

To get samples and instructions for installing them:

To access samples from Visual Studio

  • On the Help menu, click Samples.

    By default, these samples are installed in drive:\Program Files\Microsoft Visual Studio 10.0\Samples\.

  • For the most recent version of this sample and a list of other samples, see Visual Studio Samples on the MSDN Web site.

Building and Running the Sample

To build and run this sample

  1. Open the solution file atltangram.sln.

  2. From the Build menu, click Build Solution.

  3. From the Debug menu, click Start Without Debugging.

  4. A dialog box will appear: select either option. The Tangram program will begin.

Managing a Large Project

The solution has established the interdependencies in the IDE. These interdependencies work with the default directory structure for the sample and are path-relative.

The dependency hierarchy looks roughly like this:

MFCTangram
   ATLGLWorld
      ATLGdiWorld
         ATLTangramCanvas
            ATLModel
   ATLModelExe
      ATLModel
      ATLModel

All of the project settings are already established for the sample. Follow these steps to examine the project interdependencies.

  1. From the Project menu, click Properties.

  2. Select the Atltangram solution in Solution Explorer.

  3. In the Property Pages dialog box, expand the Common Properties folder and select Debug Source Files. Examine the Search these paths for source files box.

  4. Click Project Dependencies and examine the dependent project names.

The ATLModel and ATLModelExe projects demonstrate how to set up a COM server so you can build it as either an in-proc server or a local server using the same set of files and two project files. Using two project files allows dependencies to exist on both the DLL and the EXE.

COM/ATL Features

This sample is a COM system that consists of several COM servers and an MFC application that uses the servers. The sample exhibits the intermodule communication via the connection point mechanism and demonstrates local and in-proc servers.

Other Demonstrated Features

  • The ATL servers use the Standard Template Library for collections.

  • The MFC driver uses MFC template classes.

  • The MFC driver, an example of a non-document/view application, uses a class derived from CFrameWnd as the output window for the drawing the Tangram pieces.

Attributes

This sample uses the following attributes:

  • ATLTANGRAM   export, helpstring, object, pointer_default, uuid

  • ATLTANGRAM/atlgdiworld   coclass, com_interface_entry, default, dll, event_receiver, helpstring, iid_is, implements_category, in, module, name, object, out, pointer_default, progid, registration_script, size_is, unique, uuid, version, vi_progid

  • ATLTANGRAM/atlglworld   coclass, com_interface_entry, default, dll, event_receiver, helpstring, implements_category, in, module, name, object, out, pointer_default, progid, registration_script, uuid, vi_progid

  • ATLTANGRAM/atlmodel   coclass, default, dll, event_source, exe, helpstring, in, module, name, object, out, pointer_default, progid, size_is, uuid

  • ATLTANGRAM/atltangramcanvas   coclass, default, dll, helpstring, in, module, name, object, out, pointer_default, progid, registration_script, uuid, vi_progid

Classes and Keywords

The sample uses the following ATL classes:

CComObjectRootEx, CComCoClass, CComControl, IDispatchImpl, IProvideClassInfo2Impl, IPersistStreamInitImpl, IPersistStorageImpl, IPersistPropertyBagImpl, IPerPropertyBrowsingImpl, IQuickActivateImpl, IObjectSafetyImpl, IOleControlImpl, IOleObjectImpl, IOleInPlaceActiveObjectImpl, IViewObjectExImpl, IOleInPlaceObjectWindowlessImpl, IDataObjectImpl, ISupportErrorInfo, ISpecifyPropertyPagesImpl, IConnectionPointContainerImpl, IPropertyNotifySinkCP, CDialogImpl

The sample uses the following MFC classes:

CFrameWnd, CTypedPtrList<>, CDialog, CWinApp, and additional supporting classes

This sample uses the following keywords:

_ASSERTE; AddRef; AddUpdateRect; Advise; assert; ASSERT; ATLTRACE; auxSolidSphere; BEGIN_COM_MAP; BEGIN_CONNECTION_POINT_MAP; BEGIN_MESSAGE_MAP; BEGIN_OBJECT_MAP; BitBlt; CATEGORYINFO ; CComCoClass; CComModule::GetClassObject; CComModule::GetLockCount; CComModule::Init; CComModule::RegisterServer; CComModule::Term; CComModule::UnregisterServer; CComObjectRootEx; CExeModule::Init; CExeModule::RegisterClassObjects; CExeModule::RegisterServer; CExeModule::RevokeClassObjects; CExeModule::UnregisterServer; CExeModule::UpdateRegistryFromResource; CFrameWnd::AssertValid; CFrameWnd::Dump; CFrameWnd::PreCreateWindow; ChoosePixelFormat; CModelList; CoCreateInstance; CoInitializeEx; COM_INTERFACE_ENTRY; COM_INTERFACE_ENTRY_AGGREGATE; COM_INTERFACE_ENTRY_IMPL; CONNECTION_POINT_ENTRY; CopyRect; CoTaskMemFree; CProxyIATLTangramModelEvent; CreateCompatibleDC; CreatePalette; CWnd::CreateEx; DECLARE_GET_CONTROLLING_UNKNOWN; DECLARE_MESSAGE_MAP; DECLARE_ONLY_AGGREGATABLE; DECLARE_REGISTRY_RESOURCEID; DeleteObject; DescribePixelFormat; DisableThreadLibraryCalls; DispatchMessage; DoButtonDown; DoModal; END_COM_MAP; END_CONNECTION_POINT_MAP; END_MESSAGE_MAP; END_OBJECT_MAP; EqualRect; ErrorMessage; GdiFlush; GetBoundingRect; GetClientRect; GetCommandLine; GetControllingUnknown; GetDC; GetMessage; GetModuleFileName; GetObject; GetPalette; GetPaletteEntries; GetPixelFormat; GetRotation; GetVertices; glBegin; glClearColor; GLdouble; CoCreateInstance; glEnable; glEnd; glFlush; glGetIntegerv; glInitNames; glLightfv; glLightModelfv; glLoadIdentity; glMatrixMode; glNormal3d; glPolygonMode; glPopMatrix; glPopName; glPushMatrix; glPushName; GLRender; glRenderMode; GLResize; glRotated; glSelectBuffer; GLSetup; glTranslated; glTranslatef; gluPerspective; gluPickMatrix; gluUnProject; glVertex2d; glVertex3d; glViewport; HPALETTE; ICatInformation::EnumClassesOfCategories; ICatRegister::QueryInterface; ICatRegister::RegisterCategories; ICatRegister::RegisterClassImplCategories; ICatRegister::UnRegisterCategories; ICatRegister::UnRegisterClassImplCategories; IConnectionPointContainer::FindConnectionPoint; IConnectionPointContainer::Release; IConnectionPointContainerImpl; InitInstance; InvalidateRect; IsCurrent; IsValidAddress; IUnknown::Release; LoadIcon; LoadStandardCursor; LocalFree; MakeCurrent; OBJECT_ENTRY; ON_COMMAND; ON_WM_DESTROY ; OnCancel; OnDestroy; OnInitDialog; OnOK; OnQueryNewPalette; OutputDebugString; OutputGlError; Polygon; PreCreateWindow; PtInRegion; QueryInterface; RealizePalette; Release; ReleaseConnectionPoint; ReleaseDC; Rotate; SelectObject; SelectPalette; SetPixelFormat; SetRectEmpty; specifyMaterial; StringFromCLSID; SubkeyExists; va_end; wcscpy_s; wglCreateContext; wglGetCurrentContext; wglMakeCurrent

Note

Some of the samples, such as this one, have not been modified to reflect the changes in the Visual C++ wizards, libraries, and compiler, but still demonstrate how to complete your desired task.

See Also

Other Resources

ATL Attributes Samples