Share via


Creating and Initializing COM Objects (Windows CE 5.0)

Send Feedback

A thread can call the CoCreateInstance or 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.

You can activate in-process COM objects by specifying CLSCTX_ ALL or CLSCTX_SERVER.

Earlier versions of Windows CE 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

COM requires initialization of objects by calling the CoInitializeEx function before your application can use them. 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.

See Also

COM and DCOM Application Development

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.