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

Last reviewed: March 6, 1998
Article ID: Q175993
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 MFC OLE Classes offer a powerful way for Visual C++ 4.X, and 5.0 developers to use the ActiveX Data Objects (ADO) typelib and manipulate ADO objects. This article discusses how to take advantage of MFC-OLE with ADO.

MORE INFORMATION

Before You Instantiate Any Classes Created by MFC-OLE

It is important to initialize OLE before creating any instances of classes created by MFC-OLE. One way to initialize OLE is with the following code snippet:

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

If you have any global BSTR's 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, however, this value is not raised/returned by the MFC-OLE classes. You may receive a COleException or COleDispatchException. You should also check the member variable m_lpDispatch for any class derived from ColeDispatchDriver. If the member variable is NULL you should not continue executing methods of an ADO object. It is possible, for example, to generate a series of nested exceptions, which even try/catch(...)blocks cannot catch. (To see this, take the ADOVC sample mentioned below, and change the PROGID in the Connection object's CreateDispatch() call to something invalid.)

The ADOVC sample demonstrates how to catch exceptions/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 does require a license key when run on any system that has ADO installed in a mechanism other than a Microsoft product. Unlike other mechanisms within Visual C++, that work without passing a license key as long as that license key exists in the registry, MFC-OLE requires your ADO 1.0 based code to ALWAYS pass a license key.

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

   ARTICLE-ID: Q174802
   TITLE     : HOWTO: Passing a License Key to ADO in Visual C++ Using MFC-
               OLE

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


Additional query words: noupdate s_mfc

Keywords : adoall adovc
Version : WINDOWS:1.0,1.5
Platform : WINDOWS
Issue type : 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 6, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.