ATL-Based EXEs

[Previous] [Next]

Producing an EXE-based server is a little more straightforward than producing a DLL-based server because the Support MFC, Allow Merging Of Proxy/Stub Code, and the Support MTS options are turned off. EXE-based servers run in their own process space, have their own primary thread, and service the message queue. As with DLL-based servers, EXE servers perform the correct contortions to be COM servers.

Instead of exporting the well-known functions for exposing class objects, an EXE server exposes its class objects via the COM API function CoRegisterClassObject. Calls to these functions are hidden within ATL's CComModule class. Instead of exporting DllRegisterServer and DllUnregisterServer, ATL-based EXEs check the command line for /RegServer or /UnRegServer to install information in the Registry. Finally, rather than being unloaded passively (as DLLs are), an EXE server watches its reference count go up and down and unloads itself when the reference count drops to 0.

Selecting a COM-based EXE from the ATL COM AppWizard yields the following files:

  • <project name>.cpp includes the WinMain entry point. The default code generated by the ATL COM AppWizard produces an EXE that runs in the single-threaded apartment. This file also contains the single global instance of the CExeModule class that maintains the list of class objects and is responsible for registering information in the Registry.
  • <project name>.idl represents a blank IDL file awaiting interface and coclass definitions.
  • <project name>.rc includes any resources you want to include in your COM-based EXE server.
  • stdafx.h is where general #include statements go.
  • stdafx.cpp compiles the stdafx.h file.
  • resource.h includes any identifiers required by your resource script.
  • <project name>.rgs includes the Registry script code necessary to install the AppID for the EXE-based application.

Compiling the project yields three more files:

  • <project name>.h includes the C++ versions of the COM interfaces found in <project name>.idl.
  • <project name>_i.c includes the GUIDs defined in <project name>.idl.
  • <project name>.tlb is the binary description of your COM-based server (a type library).

As with a DLL-based server, an EXE server generated by the AppWizard also includes IDL code. Compiling the EXE yields enough source code to create a proxy/stub DLL capable of remoting the interfaces described within the IDL file.

Inside Atl
Inside ATL (Programming Languages/C)
ISBN: 1572318589
EAN: 2147483647
Year: 1998
Pages: 127 © 2008-2017.
If you may any questions please contact us: