ID: Q174565
The information in this article applies to:
- Microsoft Visual C++, 32-bit Editions, version 5.0
Adovc.exe is a sample that demonstrates using ActiveX Data Objects (ADO) within Visual C++ 5.0.
The following file is available for download from the Microsoft Software Library.
Note: After you click on the following link, please choose "Save this program to disk" from the File Download dialog box. Then, click Run on the Start menu and run the .exe file with the -d attribute, as in the following example:
C:\...\Adovc.exe -d
~ 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
ADOVC 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.
ARTICLE-ID: Q173645
TITLE: BUG: Access Violation in Msdaer.dll with _com_error
Exceptions
An 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.
Here 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.
Here are some disadvantages of using OLE-SDK:
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 );
Based on the three projects in this sample, the recommended preference for using ADO in Visual C++ follows:
1. #import because it dramatically simplifies using COM
2. OLE SDK because you get back HRESULTS that are otherwise buried in MFC-
OLE (when OLE SDK breaks, you know it)
3. MFC-OLE, despite being an intermediate step towards #import, hides too
much when it doesn't give you back a failed HRESULT
For additional information, please see the following article in the Microsoft Knowledge Base:
ARTICLE-ID: Q167802
TITLE : SAMPLE: EXCEPTEX Traps MFC and Win32 Structured
Exceptions
ARTICLE-ID: Q146437
TITLE : SAMPLE: Horizontal Scrolling List Box in an MFC Class
This 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 How to Use ADO with Visual C++
Q182782 FILE: Adovj.exe Demonstrates How to Use ADO with Visual J++
Q185033 FILE: Adoacc.exe Demonstrates Using ADO with Access 97
These 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++
At 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:
// ADO 1.0 Version
Conn1->Open( bstrEmpty, bstrEmpty, bstrEmpty );
// ADO 1.5 Version
// Conn1->Open( bstrEmpty, bstrEmpty, bstrEmpty, -1 );
Keywords : kbsample kbADO kbVC
Version : WINDOWS:1.0
Platform : WINDOWS
Last Reviewed: February 4, 1999