OleInitialize

Initializes the COM library on the current apartment, identifies the concurrency model as single-thread apartment (STA), and enables additional functionality described in the Remarks section below. Applications must initialize the COM library before they can call COM library functions other than CoGetMalloc and memory allocation functions.

Applications that do not require the additional functionality enabled by OleInitialize should call CoInitializeEx instead of OleInitialize.

WINOLEAPI OleInitialize(
  LPVOID pvReserved  //Reserved; must be NULL.
);
 

Parameter

pvReserved
[in] Reserved; must be NULL.

Return Values

This function supports the standard return values E_INVALIDARG, E_OUTOFMEMORY, and E_UNEXPECTED, as well as the following:

S_OK
The COM library and additional functionality were initialized successfully on this apartment.
S_FALSE
The COM library is already initialized on this apartment.
OLE_E_WRONGCOMPOBJ
The versions of COMPOBJ.DLL and OLE2.DLL on your machine are incompatible with each other.
RPC_E_CHANGED_MODE
A previous call to CoInitializeEx specified the concurrency model for this apartment as multithread apartment (MTA).

Remarks

Applications that use the following functionality must call OleInitialize before calling any other function in the COM library:

OleInitialize calls CoInitializeEx internally to initialize the COM library on the current apartment. Because OLE operations are not thread-safe, OleInitialize specifies the concurrency model as single-thread apartment.

Once the concurrency model for an apartment is set, it cannot be changed. A call to OleInitialize on an apartment that was previously initialized as multithreaded will fail and return RPC_E_CHANGED_MODE.

You need to initialize the COM library on an apartment before you call any of the library functions except CoGetMalloc, to get a pointer to the standard allocator, and the memory allocation functions.

Typically, the COM library is initialized on an apartment only once. Subsequent calls will succeed, as long as they do not attempt to change the concurrency model of the apartment, but will return S_FALSE. To close the COM library gracefully, each successful call to OleInitialize, including those that return S_FALSE, must be balanced by a corresponding call to OleUninitialize.

If OleInitialize returns OLE_E_WRONGCOMPOBJ, either COMPOBJ.DLL or OLE2.DLL has been updated to a version that is incompatible with the other file. To correct this problem, replace both of these files with versions for your operating system from the same release of the Platform SDK.

QuickInfo

  Windows NT: Use version 3.1 or later.
  Windows: Use Windows 95 or later.
  Windows CE: Unsupported.
  Header: Declared in ole2.h.
  Import Library: Included as a resource in ole32.dll.

See Also

OleUninitialize, CoInitialize, CoInitializeEx