Microsoft KB Archive/176342

= INFO: Using ActiveX Data Objects (ADO) via OLE SDK in VC++ =

Article ID: 176342

Article Last Modified on 3/2/2005

-

APPLIES TO


 * Microsoft ActiveX Data Objects 1.0
 * Microsoft ActiveX Data Objects 1.5
 * Microsoft ActiveX Data Objects 2.0
 * Microsoft ActiveX Data Objects 2.1
 * Microsoft ActiveX Data Objects 2.1 Service Pack 2

-



This article was previously published under Q176342



SUMMARY
The OLE DB 1.x SDK and Data Access 2.x SDK contain two files, Adoid.h and Adoint.h, which make using ActiveX Data Objects (ADO) easier with the OLE DB SDK. This article discusses how to utilize the header files effectively.



Using ADOID.H and ADOINT.H
For ADO 1.x, add the \Oledbsdk\Include and \Oledbsdk\Lib folders to your path. For ADO 1.0 or 1.1 add Adoid.lib to the link step. For ADO 1.5 and later you need to explicitly remove this .lib file, and add an include to , once in your application, prior to including theADOID.H/ADOINT.H file(s).

You may see the following warning message upon compilation:

 adoid.lib(adoid.obj) : warning LNK4099: PDB "dao40.pdb" was not found with "c:\oledbsdk\lib\adoid.lib" or at ; linking object as if no debug info This message can be ignored.

Before Instantiating any ADO Objects
It is important to initialize OLE before creating any instances of ADO objects using the OLE SDK. You may use the following code snippet:

struct InitOle { InitOle { ::CoInitialize(NULL); } ~InitOle { ::CoUninitialize;  } } _init_InitOle_;

If you have any global BSTRs, this is also a good place to allocate and deallocate them.

Error Handling
With ADO, you may receive an error in the HRESULT returned from an ADO method. This may or may not result in errors being filled in the ADO Errors Collection. The Errors collection only receives errors raised by the underlying provider (or drivers underneath that provider.) ADO errors are not populated in the collection but can be retrieved from the IErrorInfo interface.

The Adovc sample demonstrates how to catch exceptions or errors with ADO.

For additional information, please see the following article in the Microsoft Knowledge Base:

220152 Sample: ADOVC1 Simple ADO/VC++ Application

Passing the License Key to ADO and ADO Redistribution
ADO 1.0 requires a license key when run on any system that has ADO installed in a mechanism other than a Microsoft product. If the license key is already installed in the registry, then you do not need to pass a license key. Otherwise, instead of CoCreateInstance, you use CoGetClassObject to get a IClassFactory2 interface and CreateInstanceLic. ADO 1.5 removed the need for a license key.

