HRESULT MyClassFactory::RegisterClassObject(DWORD dwClsContext, DWORD flags) { HRESULT hr = S_OK; hr = pModule->RegisterClassObject( m_clsid, // GUID of the object to register this, // pointer to the IClassFactory implementation dwClsContext, // context in which object will be created flags, // flags to control registration behavior &m_dwRegister); // [out] assigned registration identifier return hr; }
CComModule _Module; int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { HRESULT hr; hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); if (FAILED(hr)) return 1; hr = _Module.Init(NULL, hInstance); if (FAILED(hr)) { CoUninitialize(); return 1; } // do some work with COM objects _Module.Term(); CoUninitialize(); return 0; }The package library for CComModule is the Microsoft Visual C++ COM library. It is bundled with Microsoft Visual Studio.