HOWTO: Return ADO/RDS/OLE DB Interfaces from COM ObjectsLast reviewed: January 21, 1998Article ID: Q178841 |
The information in this article applies to:
SUMMARYThe OLE DB Software Development Kit (SDK) provides IDL files for OLE DB objects (in the directory \Oledbsdk\Unsupported\Idl), but not for ActiveX Data Objects (ADO) or the Remote Data Service (RDS). This makes it difficult to return these objects either as an argument within a method, or as the return value of a method within a C++ COM object. This article presents two techniques that can be used to accomplish either objective.
MORE INFORMATIONMethod 1: Create Your Own IDL File You can create your own .idl file by using the Oleview.exe application that comes with Visual C++. For example, if you open the type library for ADO, you see an .idl file for that type library in the OLEVIEW window. Another way to handle this is to create a "dummy" .idl file for a given MDAC interface. Within this .idl file you define an interface for each object you want to use. Each interface uses the same UUID as the real interface, and you will not define any methods or properties for these dummy interfaces. In the code below, a dummy interface is created for the ADODB.Recordset:
import "oaidl.idl"; [ object, uuid(00000243-0000-0010-8000-00AA006D2EA4), dual, pointer_default(unique) ] interface ADORecordset : IDispatch { // No methods defined. fake! };Now you can save this as a separate .idl file (Adiint.idl, for example.) Below is a sample IDL snippet that demonstrates how it would be used:
import "adoint.idl"; // fake interfaces interface IServer : IDispatch { [id(1), helpstring("Send a recordset to the wire")] HRESULT SendRecordset( [in] ADORecordset *pIADORecordset, [in, defaultvalue(1)] long lRows ); ... }; Method 2: Use IDispatchYou can avoid the need for creating your own .idl file by returning an Idispatch pointer from your method instead of a custom interface. The client will then QueryInterface() for the interface it needs or will invoke methods using the IDispatch interface.
REFERENCES
Keywords : kbcode Technology : ole Version : WINDOWS:1.0,1.1,1.5 Platform : WINDOWS Issue type : kbhowto |
================================================================================
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |