Share via


Creating and Initializing COM Objects

A thread can call the CoCreateInstance or the CoGetClassObject function to create a new instance of a component. In Windows CE, the dwClsContext parameter in those calls must be set to CLSCTX_ INPROC_SERVER.

Beginning with Windows CE 2.12, you can activate in-process COM objects by specifying either CLSCTX_ ALL or CLSCTX_SERVER; earlier versions of Windows CE will return an E_NOTIMPL error if the flag is not set explicitly to CLSCTX_INPROC_SERVER. Additionally, the COSERVERINFO parameter in the call to the CoGetClassObject function must be NULL, because in its minimal implementation, COM on Windows CE does not support remote servers. The following code example shows the function call.

IClassFactory* pFactory = NULL;
 ::CoGetClassObject(CLSID_MyObject,
                    CLSCTX_INPROC_SERVER, NULL,
                    IID_ICLASSFACTORY, (LPVOID*)        
                    &pFactory);
 pFactory->CreateInstance(NULL,IID_IMyObject,
                          (LPVOID*) m_pObj);

Initializing COM Objects

The Windows CE .NET implementation of COM requires that you initialize objects by calling the CoInitializeEx function before you can use them. Furthermore, calls to CoInitializeEx and CoUninitialize are reference counted and should match one for one, as described in the documentation. For more information, see CoUninitialize.

Earlier versions of Windows CE do not enforce object initialization, but it is still recommended that you initialize all objects.

Last updated on Wednesday, April 13, 2005

© 2005 Microsoft Corporation. All rights reserved.