HOWTO: Return ADO/RDS/OLE DB Interfaces from COM Objects

Last reviewed: January 21, 1998
Article ID: Q178841
The information in this article applies to:
  • Microsoft Data Access Components, version 1.5
  • Microsoft OLE DB, versions 1.0, 1.1, 1.5
  • Remote Data Service for ADO versions 1.0, 1.1, 1.5
  • ActiveX Data Objects (ADO), versions 1.0, 1.5

SUMMARY

The 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 INFORMATION

Method 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 IDispatch

You 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

http://www.microsoft.com/data

Keywords          : kbcode
Technology        : ole
Version           : WINDOWS:1.0,1.1,1.5
Platform          : WINDOWS
Issue type        : kbhowto


================================================================================


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: January 21, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.