The information in this article applies to:
SUMMARYADOEvts.exe is a sample that demonstrates how to capture events from Microsoft Active Data Objects (ADO). The ADO events in this sample were added with ADO version 2.0. MORE INFORMATIONThe following file is available for download from the Microsoft
Download Center. Click the file name below to download the file: ADOEVTS.EXEFor more information about how to download files from the Microsoft Download Center, please visit the Download Center at the following Web address http://www.microsoft.com/downloads/search.aspand then click How to use the Microsoft Download Center. To build the sample, run ADOEvts.exe, open the ADOEvts.cpp file in the Visual C++ environment, and build. When you receive a message asking if you would like to create a default project workspace click Yes. The #import of MSADO15.dll might have to be redirected if you do not have a "Program Files" directory on your C: drive. You need to make a DataSource called "AccessTest" on the system that is pointing to the Test.mdb file provided with this sample. After you run the console application, the events are shown in the Visual C++ Output window. Follow these steps to capture ADO events in Visual C++:
Creating the Event ClassesThe first step to handling ADO events is to create the sink classes that will handle the events. To do this, you must create a Visual C++ class derived from either RecordsetEventsVt or ConnectionEventsVt, depending upon the events you want to capture. The RecordsetEventsVt and ConnectionEventsVt interfaces are defined in ADOInt.h, which comes with the Microsoft Data Access SDK or Visual Studio version 6.0. The sample shows both of the classes in ADOConnEvts.h and ADORSEvts.h. They are called CADOConnectionEvents and CADORecordsetEvents respectively. Following is the connection event class:
Notice that you must implement Iunknown. Also, notice that all of the
methods return adStatusUnwantedEvent. This tells ADO to not call the event
handler again. This gives you a generic class that you can derive from and
then only override the events that you want to handle. All other events are
only be called once because of the adStatusUnwantedEvent return value. You
can see in ADOEvents.cpp that there are 2 classes derived from these
classes: CCnEvents and CRSEvents. These are the classes that you will use
to create the event objects. Their methods contain an OutputDebugString
message for each event so you can view the events in the output window of
the debugger.
Connecting an Event Object to ADOThe ADOEvts.cpp file demonstrates how to connect an event object to an ADO connection or recordset. Four functions are defined: SetConnectionEvents(), SetRSEvents(), ClearRSEvents(), and ClearConnectionEvents(). Following is and example of how the functions are used in the main() function:
In the code above you can see that an interface pointer to the connection
and recordset objects is passed to SetConnectionEvents and SetRSEvents
respectively. These functions create a connection event or recordset event
object and connect it to the ADO object.
Following is the code for SetConnectionEvents():
Note that UUIDs come from "ConnectionEvents" and "RecordsetEvents". The
connection points QueryInterface() the event object you pass to the
Advise() call for ConnectionEventsVt or RecordsetEventsVt.
Also, further notice that the pointer, "new CCnEvents", is passed directly to the Advise call. The event object is freed when its Release() method is called in the connection point Unadvise() call in ClearConnectionEvents(). Additional query words:
Keywords : kbfile kbsample kbADO200 kbDatabase kbSDKDataAc kbGrpVCDB kbGrpMDAC kbDSupport |
Last Reviewed: November 13, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |