DetailPage-MSS-KB

Microsoft small business knowledge base

Article ID: 175993 - Last Review: October 26, 2013 - Revision: 3.0

This article was previously published under Q175993
This article has been archived. It is offered "as is" and will no longer be updated.

On This Page

Summary

The Microsoft Foundation Classes (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 Instantiating 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:

220152  (http://support.microsoft.com/kb/220152/EN-US/ ) Sample: ADOVC1 Simple ADO/VC++ Application

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.

References

Rogerson, Dale. Inside COM. Microsoft Press, February 1997, (ISBN 1-57231-349-8).

For additional information, click the following article number to view the article in the Microsoft Knowledge Base:
168354  (http://support.microsoft.com/kb/168354/EN-US/ ) INFO: Underlying OLE and OLEDB Provider Errors Are Exposed Through ADO
Keywords: 
kbnosurvey kbarchive kbdatabase kbinfo KB175993
Share
Additional support options
Ask The Microsoft Small Business Support Community
Contact Microsoft Small Business Support
Find Microsoft Small Business Support Certified Partner
Find a Microsoft Store For In-Person Small Business Support