FILE: Adovc.exe Demonstrates How to Use ADO with Visual C++Last reviewed: March 6, 1998Article ID: Q174565 |
The information in this article applies to:
SUMMARYAdovc.exe is a sample that demonstrates using ActiveX Data Objects (ADO) within Visual C++ 5.0.
MORE INFORMATIONThe following file is available for download from the Microsoft Software Library:
~ Adovc.exe (size: 312617 bytes)For more information about downloading files from the Microsoft Software Library, please see the following article in the Microsoft Knowledge Base:
ARTICLE-ID: Q119591 TITLE : How to Obtain Microsoft Support Files from Online Services What ADOVC DemonstratesADOVC is a sample that demonstrates using ActiveX Data Objects (ADO) within Visual C++ 5.0. Demonstration code for each of ADO's six classes is presented, with some additional code for handling more common issues such as output/return parameters and error/exception handling. This sample actually has three separate projects, one for each of the three techniques that can be used with ADO inside Visual C++:
Three files in each sample contain all ADO specific code:
Adoutils.h - Contains the declaration of error/exception functions, helper functions, and is where ADO declarations are included in the project. Adoutils.cpp - Implementation of error/exception and helper functions. Adocore.cpp - Actual ADO sample code, where ADO is demonstrated. Advantages of Using #import
Disadvantages of Using #import
Advantages of Using MFC-OLEAn advantage of using MFC-OLE is that it hides BSTR and VARIANTS from implementor, methods that return these types are modified so that the actual wrapper class returns a CString.
Disadvantages of Using MFC-OLEHere are some disadvantages of using MFC-OLE:
possible to receive failed HRESULTS bundled inside a ColeDispatchDriver exception, but there are scenarios where HRESULTS may not be received. It is also important that the exception handling, if it uses the Connection object's Errors collection, not process this collection unless you have a valid connection object. Otherwise it may be possible to generate exceptions within your exception handler. Advantages of Using OLE-SDK
Disadvantages of Using OLE-SDKHere are some disadvantages of using OLE-SDK:
#import and the Advantage of "VB-Like Syntax"Consider the following three code fragments to get the ActualSize property of a Field object, starting from the Recordset object:
// #import CString strTmp; strTmp.Format( "\t\t...Actual Size = %ld", Rs1->Fields->Item[_variant_t((long)0)]->ActualSize );One line of code to go from Recordset to the ActualSize property. Now consider MFC-OLE:
// MFC-OLE CString strTmp; Fields Flds1 Field Fld1; Flds1 = Rs1.GetFields(); Fld1 = Flds1.GetItem( COleVariant( (long) 0 ) ); strTmp.Format( "\t\t...Actual Size = %ld", Fld1.GetActualSize );Finally, consider the OLE-SDK equivalent code, which is nearly the same size as MFC-OLE, but gives more immediate error handling results than MFC- OLE is capable of.
// OLE-SDK with ADOID.H and ADOINT.H CString strTmp; ADOFields* Flds1 = NULL; ADOField* Fld1 = NULL; long nTmp; if( SUCCEEDED ( hr ) ) hr = Rs1->get_Fields( & Flds1 ); if( SUCCEEDED ( hr ) ) hr = Flds1->get_Item( COleVariant((long) 0 ), &Fld1 ); if( SUCCEEDED ( hr ) ) hr = Fld1->get_ActualSize( &nTmp ); if( SUCCEEDED ( hr ) ) strTmp.Format( "\t\t...Actual Size = %ld", nTmp ); #import vs. COleDispatchDriver vs. OLE SDKBased on the three projects in this sample, the recommended preference for using ADO in Visual C++ follows:
Other Tips for Using VC and ADO
About the ADO* Series of SamplesThis is one of several identical samples implemented using ADO within various products, as listed below. The advantage is that these articles have an identical interface/functionality, demonstrating both the similarities differences in using ADO with different languages and with different mechanisms within that language (where applicable).
QNumber Title ------- ---------------------------------------------------- Q172403 FILE: Adovb.exe Demonstrates How to Use ADO with Visual Basic Q174565 FILE: Adovc.exe Demonstrates Using ADO with Visual C++ Other Knowledge Base Articles of NoteThese articles provide detailed information not covered in this text about using ADO with various Visual C++ implementation mechanisms.
QNumber Title ------- ---------------------------------------------------------- Q169496 INFO: Using ActiveX Data Objects (ADO) via #import in VC++ Q175993 INFO: Using ActiveX Data Objects (ADO) via MFC OLE in VC++ Q176342 INFO: Using ActiveX Data Objects (ADO) via OLE SDK in VC++ ADO Version 1.5At the time of the writing of this sample, ADO 1.5 was not yet released, but was available publicly in beta. This sample has been written to work with either version, but there are some differences:
Keywords : adovc Version : WINDOWS:1.0,1.5 Platform : WINDOWS Issue type : kbfile Solution Type : kbsample |
================================================================================
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |