Important: |
---|
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist. |
This function creates on the local system a single uninitialized object of the class associated with a specified class identifier.
STDAPI CoCreateInstance( REFCLSID rclsid , LPUNKNOWN pUnkOuter , DWORD dwClsContext , REFIID riid , LPVOID * ppv );
Parameters
Return Values
One of the values described in the following table is returned.
Value | Description |
---|---|
S_OK | An instance of the specified object class was successfully created. |
REGDB_E_CLASSNOTREG | A specified class is not registered in the registration database. Also can indicate that the type of server you requested in the CLSCTXenumeration is not registered or the values for the server types in the registry are corrupt. |
CLASS_E_NOAGGREGATION | This class cannot be created as part of an aggregate. |
Remarks
The CoCreateInstancehelper function provides a convenient shortcut by connecting to the class object associated with the specified class identifier, creating an uninitialized instance, and releasing the class object. As such, it encapsulates the following functionality:
CoGetClassObject(rclsid, dwClsContext, NULL, IID_IClassFactory, &pCF); hresult = pCF->CreateInstance(pUnkOuter, riid, ppvObj) pCF->Release();
It is convenient to use CoCreateInstancewhen you need to create only a single instance of an object on the local machine. When you are creating multiple instances, it is more efficient to obtain a pointer to the class object's IClassFactoryinterface and use its methods as needed. In the latter case, you should use the CoGetClassObjectfunction.
In the CLSCTXenumeration, you can specify the type of server used to manage the object. The constants can be CLSCTX_INPROC_SERVER, CLSCTX_INPROC_HANDLER, CLSCTX_LOCAL_SERVER, or any combination of these values. The constant CLSCTX_ALL is defined as the combination of all three. For more information about the use of one or a combination of these constants, refer to CLSCTX.
Passing into this function any invalid and, under some circumstances, NULL pointers result in unexpected termination of the application.
Requirements
Runs On | Versions | Defined in | Include | Link to |
---|---|---|---|---|
Windows CE OS | 2.0 and later | Objbase.h |
Note This API is part of the complete Windows CE OS package as provided by Microsoft. The functionality of a particular platform is determined by the original equipment manufacturer (OEM) and some devices may not support this API.
See Also
CoGetClassObject, IClassFactory, IUnknown