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

Last reviewed: March 5, 1998
Article ID: Q176342
The information in this article applies to:
  • ActiveX Data Objects (ADO), versions 1.0, 1.5 included with:

        - Microsoft Visual C++, 32-bit Editions, versions 4.2, 4.2b, 5.0
    

SUMMARY

The OLE DB SDK contains 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.

MORE INFORMATION

Using ADOID.H and ADOINT.H

Add the \Oledbsdk\Include and \Oledbsdk\Lib folders to your path and add Adoid.lib to the link step. You may see this warning message upon compilation:

   adoid.lib(adoid.obj) : warning LNK4099: PDB "dao40.pdb" was not found
                          with "c:\oledbsdk\lib\adoid.lib" or at <path>;
                          linking object as if no debug info

This message can be ignored.

Before You Instantiate Any Classes Created by OLE SDK

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:

   ARTICLE-ID: Q174565
   TITLE     : FILE: Adovc.exe Demonstrates How to Use ADO with Visual C++

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().

REFERENCES

  • "Inside COM" by Dale Rogerson ISBN 1-57231-349-8

For more information, see the following articles in the Microsoft Knowledge Base:

   ARTICLE-ID:  Q168122
   TITLE:       HOWTO: Redistribute ADO 1.0 or ADO/R 1.0 with OLE/DB 1.1

   ARTICLE-ID:  Q168354
   TITLE     :  INFO: Underlying OLE and OLEDB Provider Errors Exposed via
                ADO

   ARTICLE-ID: Q169496
   TITLE     : INFO: Using ActiveX Data Objects (ADO) via #import in VC++


   ARTICLE-ID: Q175993
   TITLE     : INFO: Using ActiveX Data Objects (ADO) via MFC OLE in VC++


   ARTICLE-ID: Q176342
   TITLE     : INFO: Using ActiveX Data Objects (ADO) via OLE SDK in VC++




Keywords          : adoall adovc
Version           : WINDOWS:1.0,1.5
Platform          : WINDOWS
Issue type        : kbhowto kbinfo


================================================================================


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: March 5, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.