Share via


CComObjectRootEx::ObjectMain

For each class listed in the object map, this function is called once when the module is initialized, and again when it is terminated.

static void WINAPI ObjectMain( 
   bool bStarting  
);

Parameters

  • bStarting
    [out] The value is true if the class is being initialized; otherwise false.

Remarks

The value of the bStarting parameter indicates whether the module is being initialized or terminated. The default implementation of ObjectMain does nothing, but you can override this function in your class to initialize or clean up resources that you want to allocate for the class. Note that ObjectMain is called before any instances of the class are requested.

ObjectMain is called from the entry point of the DLL, so the type of operation that the entry-point function can perform is restricted. For more information on these restrictions, see Run-Time Library Behavior and DllMain.

Example

class ATL_NO_VTABLE CMyApp :
   public CComObjectRootEx<CComSingleThreadModel>,
   public CComCoClass<CMyApp, &CLSID_MyApp>,
   public IMyApp
{
public:
   CMyApp()
   {
   }

   static void WINAPI ObjectMain(bool bStarting)
   {
      if (bStarting)
         ;// Perform custom initialization routines
      else
         ;// Perform custom termination routines
   }

   // Remainder of class declaration omitted.

Requirements

Header: atlcom.h

See Also

Reference

CComObjectRootEx Class