次の方法で共有


Creating and Initializing COM Objects (Windows Embedded CE 6.0)

1/6/2010

A thread can call the CoCreateInstance or CoGetClassObject function to create a new instance of a component.

In Windows Embedded 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 Embedded 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 Embedded 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 Embedded CE do not enforce object initialization, but it is still recommended that you initialize all objects.

See Also

Concepts

COM and DCOM Application Development