Creating a Project

[Previous] [Next]

You have two AppWizard options for creating a Win32 project that is a suitable starting point for building an ATL application.

The first option is to create an EXE server by using the ATL COM AppWizard. This choice is good if you think you might want your application to support Automation. Naturally, all the ATL wizards will work right off the bat.

The second option is to create a simple application by using the Win32 EXE Application wizard and then manually add ATL support. This choice involves a little more work if you want to use the ATL object and message wizards because certain files and statements must be present in the project before they will run. The changes required to enable the wizards are described in the following list.

  • Modify stdafx.h to add the necessary ATL headers; atlcom.h is required for the object map macros, and atlwin.h is, of course, for windowing classes. You also need an external reference to a CComModule instance, _Module. The code is as follows:
  •  #include <atlbase.h> extern CComModule _Module; #include <atlcom.h> #include <atlwin.h> 

  • Add an ATL object map to the main .cpp file. The map can be empty. Also add the CComModule instance, as shown here:
  •  CComModule _Module; BEGIN_OBJECT_MAP(ObjectMap) END_OBJECT_MAP() 

  • Add an IDL file with the same name as the project. The file must have a library block. The file doesn't have to compile, but you must add it to your project under the source files folder. Use the project settings to exclude the IDL file from your build. The file can have the following minimal contents:
  •  library AnyNameWillDo { }; 

Using the second option, we now have a lightweight application shell to which we can begin adding functionality.



Inside Atl
Inside ATL (Programming Languages/C)
ISBN: 1572318589
EAN: 2147483647
Year: 1998
Pages: 127

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net