Initializing the COM Library

Before your program can use SQL-DMO objects, the COM library must be initialized.

Visual Basic

Your SQL-DMO program does not need to initialize OLE. Visual Basic automatically initializes OLE and the COM library.

C++

All SQL-DMO and OLE functions return an HRESULT value. The HRESULT contains information about the success or failure of the SQL-DMO or OLE function. You can declare a single HRESULT variable and re-use it. For example:

HRESULT hr;

Before calling any SQL-DMO or COM functions, your SQL-DMO program must initialize the COM library by using the OLE CoInitialize function. For example:

hr = CoInitialize (NULL);

You must pass NULL to CoInitialize.

To initialize OLE you can use the OleInitialize function. This automatically initializes the COM library. For more information about OLE functions, see your OLE programming documentation.