Software & Finance





VC++ ATL/COM - Step 2 Understanding ATL / COM Source Code Generated by Wizard





 

2. Understanding ATL / COM Source Code Generated by Wizard

 

The following is the idl (interface definition language) file generated by VS2005 wizard.

  

// SFTComServer.idl : IDL source for SFTComServer  

import "oaidl.idl";

import "ocidl.idl"; 

[

      uuid(CEF82C0A-246B-4869-A44E-0707CCD480F7),b

      version(1.0),

      helpstring("SFTComServer 1.0 Type Library")

]

library SFTComServerLib

{

      importlib("stdole2.tlb");

};

COM Server DLL module code

The following is the source code for CAtlDllModuleT<CSFTComServerModule>.

 

class CSFTComServerModule : public CAtlDllModuleT< CSFTComServerModule >

{

public :

      DECLARE_LIBID(LIBID_SFTComServerLib)

      DECLARE_REGISTRY_APPID_RESOURCEID(IDR_SFTCOMSERVER, "{FD8F71C1-114B-4BAB-B71E-3BA7B0E95CC7}")

};

 

The macros will get expanded like below at compile time

 

      #define DECLARE_LIBID(libid) \

      static void InitLibId() throw() \

      { \

            ATL::CAtlModule::m_libid = libid; \

      }

 

      #define DECLARE_REGISTRY_APPID_RESOURCEID(resid, appid) \

      static LPCOLESTR GetAppId() throw() \

      { \

            return OLESTR(appid); \

      } \

      static TCHAR* GetAppIdT() throw() \

      { \

            return _T(appid); \

      } \

      static HRESULT WINAPI UpdateRegistryAppId(BOOL bRegister) throw() \

      { \

            ATL::_ATL_REGMAP_ENTRY aMapEntries [] = \

            { \

                  { OLESTR("APPID"), GetAppId() }, \

                  { NULL, NULL } \

            }; \

            return ATL::_pAtlModule->UpdateRegistryFromResource(resid, bRegister, aMapEntries); \

      }

 

Click here to download the complete source code of COM DLL Server, C++ Client and CSharp Client