Share this page

# lrc_CoCreateInstance

Creating Instances

Creates an instance of an object and returns the unknown interface.

    HRESULTlrc_CoCreateInstance( GUID * pClsid, IUnknown * pUnkOuter, unsigned long dwClsContext, GUID * riid, LPVOID * ppv, BOOL __CheckResult );

*pClsid | A pointer to the CLSID associated with the data and code that will be used to create the object.
*pUnkOuter | If NULL, indicates that the object is not being created as part of an aggregate. If non-NULL, it is a pointer to the aggregate object's IUnknown interface (the controlling IUnknown).
dwClsContext | Context in which the code that manages the newly created object will run. The values are taken from the enumeration CLSCTX and refer to in process, local, remote or combinations of these.
*riid | A pointer to the identifier of the interface to be used to communicate with the object.
*ppv | A pointer that receives the interface pointer requested in riid. Upon successful return, *ppv contains the requested interface pointer.
__CheckResult | This flag is generated by VuGen to indicate if the call was successful when the script was generated and HRESULT should be checked. Values: CHECK_HRES or DONT_CHECK_HRES.

The lrc_CoCreateInstance function creates a single uninitialized object on either the local system or on the default host configured for the object and returns the unknown interfaces, which can be used to get other interfaces. After creating the instance, VuGen calls lrc_CoGetClassObject to retrieve the interfaces. If the COM object is on a remote machine, then lrc_CreateInstanceEx is used instead of lrc_CoCreateInstance.

This function returns HRESULT. You can use this return value in code that you write, but VuGen processes it internally and does not show it in scripts. Consult Microsoft documentation for further details.

## Return Values

lrc Return Values

## Parameterization

You cannot use standard parameterization for any arguments in this function.

## Example

This extended example shows how to used GUID to get the PROGID of the COM object to be created, and how to initialize all other necessary parameters.

Copy code

    GUID pClsid = lrc_GUID("student.student.1");
    IUnknown * pUnkOuter =(IUnknown*)NULL;
    unsigned long dwClsContext = lrc_ulong("7");
    GUID riid = IID_IUnknown;
    lrc_CoCreateInstance(&pClsid, pUnkOuter, dwClsContext, &riid,(void**)&IUnknown_0, CHECK_HRES);

Tips to improve your search results... VuGen Function Reference Version 26.1-26.3 Function Reference 26.1-26.3 All View Local Help Center View Online Help Center Version: