OLE32 Functions
This section details the functions available in the OLE32.dll library, which provides core support for OLE (Object Linking and Embedding) and COM (Component Object Model) technologies in Windows.
Core OLE Functions
- CoCreateInstance
- CoInitialize
- CoUninitialize
- CoGetClassObject
- CoRegisterClassObject
- CoRevokeClassObject
- StringFromGUID2
- CLSIDFromString
Moniker and Binding Functions
Structured Storage Functions
CoCreateInstance
Creates a single, uninitialized object of the specified type and, optionally, commits it to the running object table (ROT).
HRESULT CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID riid, LPVOID *ppv);
Parameters
Name | Type | Description |
---|---|---|
rclsid |
REFCLSID |
A reference to the CLSID of the object to be created. |
pUnkOuter |
LPUNKNOWN |
If NULL , this parameter indicates that the object is not being created as part of an aggregate. If non-NULL , this parameter is a pointer to the aggregatee's controlling unknown. |
dwClsContext |
DWORD |
The context in which the code that creates the executable object will run. |
riid |
REFIID |
A reference to the IID of the interface to be used to communicate with the newly created object. |
ppv |
LPVOID * |
An indirect pointer to the interface specified in riid . Upon successful return, *ppv contains the pointer to the queried interface. |
Return Value
If the function succeeds, the return value is S_OK
. Otherwise, it is an error code.
CoInitialize
Initializes the COM library for the current apartment.
HRESULT CoInitialize(LPVOID pvReserved);
Parameters
Name | Type | Description |
---|---|---|
pvReserved |
LPVOID |
Reserved. Must be NULL . |
Return Value
If the function succeeds, the return value is S_OK
. If the COM library is already initialized, the function returns S_FALSE
. Otherwise, it is an error code.
You must call CoInitializeEx
or CoInitialize
on each thread that uses COM. It is recommended to use CoInitializeEx
with the appropriate concurrency model.
CoUninitialize
Closes the COM library.
void CoUninitialize(void);
Remarks
This function closes the COM library. It should be called once for every successful call to CoInitializeEx
or CoInitialize
.
CoGetClassObject
Provides a way to connect to a class object of the specified class.
HRESULT CoGetClassObject(REFCLSID rclsid, DWORD dwClsContext, LPCOSERVERINFO pServerInfo, REFIID riid, LPVOID *ppv);
Parameters
Name | Type | Description |
---|---|---|
rclsid |
REFCLSID |
A reference to the CLSID of the class object to retrieve. |
dwClsContext |
DWORD |
The context in which the executable code is to be run. |
pServerInfo |
LPCOSERVERINFO |
A pointer to a COSERVERINFO structure that specifies the server to connect to. Can be NULL . |
riid |
REFIID |
A reference to the interface identifier of the desired interface. |
ppv |
LPVOID * |
An indirect pointer to the interface identifier specified by riid . |
Return Value
If the function succeeds, the return value is S_OK
. Otherwise, it is an error code.
CoRegisterClassObject
Registers an application's class object with OLE so that it can be used to create instances of the class.
HRESULT CoRegisterClassObject(REFCLSID rclsid, LPUNKNOWN pUnk, DWORD dwClsContext, DWORD flags, LPDWORD pdwRegister);
Parameters
Name | Type | Description |
---|---|---|
rclsid |
REFCLSID |
The CLSID of the class being registered. |
pUnk |
LPUNKNOWN |
A pointer to the class object's implementation of the IClassFactory interface. |
dwClsContext |
DWORD |
The context in which the executable code is to be run. |
flags |
DWORD |
One of the REGCLS enumeration values. |
pdwRegister |
LPDWORD |
A pointer to a value that identifies the registered class. This value can be passed to CoRevokeClassObject . |
Return Value
If the function succeeds, the return value is S_OK
. Otherwise, it is an error code.
CoRevokeClassObject
Removes a class object's registration from the OLE component object model's central registration database.
HRESULT CoRevokeClassObject(DWORD dwRegister);
Parameters
Name | Type | Description |
---|---|---|
dwRegister |
DWORD |
The registration number obtained from a previous call to CoRegisterClassObject . |
Return Value
If the function succeeds, the return value is S_OK
. Otherwise, it is an error code.
StringFromGUID2
Converts a GUID into a string representation.
int StringFromGUID2(REFGUID rguid, LPOLESTR lpsz, int cchMax);
Parameters
Name | Type | Description |
---|---|---|
rguid |
REFGUID |
The GUID to convert. |
lpsz |
LPOLESTR |
A pointer to the buffer that receives the string representation of the GUID. |
cchMax |
int |
The size of the buffer pointed to by lpsz , in characters. |
Return Value
If the function succeeds, the return value is the number of characters in the string, including the null terminator. If the buffer is too small, the return value is 0, and the contents of the buffer are undefined. Otherwise, it is an error code.
CLSIDFromString
Converts a string representation of a CLSID into a CLSID
structure.
HRESULT CLSIDFromString(LPOLESTR lpsz, LPCLSID pclsid);
Parameters
Name | Type | Description |
---|---|---|
lpsz |
LPOLESTR |
A pointer to the string representation of the CLSID. |
pclsid |
LPCLSID |
A pointer to the CLSID structure that will receive the converted CLSID. |
Return Value
If the function succeeds, the return value is S_OK
. Otherwise, it is an error code.