Forum Chat


Mar23,13:31 Johan Marechal
Wees gegroet
Sep20,17:50 Vicente Duque
Kim, Martin, Others :...
Jul07,11:10 Johan Marechal
PGP 9
Jul05,21:13 martin
Fastest in the bush
Jul05,07:48 martin
Spamdexing
Jun28,21:16 martin
New domain / new blog!
Jun28,21:11 martin
On posting etiquette

(Note: also check out Kim Nevelsteen's notes on IDL)

msado15 treatment in the IDL

Comment on this article

If you use msado15 definitions in one component and want to use that component in another component that also independently needs to use msado15, you're in for an interesting experience. A typical example would be that you have one COM dll connecting to a database and constructing recordsets while your second COM dll gets the recordsets from the first and proceeds to do something with them. Naturally, both the first and the second COM dll need to import the ADO definitions of recordsets in several places.

After much back-and-forth, I think I've got this working by including and importing as follows.

First COM DLL

This one only utilizes ADO and is, in turn, used by the second COM DLL. The important lines are marked in red.

  • The MSADO15 is pulled in using "importlib" instead of doing "import msado15.idl", which means that the types in msado15 will not go into the qcdal (name of this example) typelibrary. Also (IMHO), it makes you use only one version of msado15, instead of running into the conflicts between msado15.dll on your system and whatever msado15.idl and adoint.h files the compiler happens to find during the compile.
  • In one of the interfaces, a type is used (_Connection) that is defined in msado15.
  • To satisfy all the places in your program that include the qse.h header file (in my example) and don't use msado, you have to include the forward declaration of "struct _Connection;"
  • Finally, in the files where you do use msado, add the following to the header or cpp:
#import "\program files\common files\system\ado\msado15.dll" no_namespace rename("EOF", "adoEOF")

Here's an excerpt from the IDL file:

// QcDAL.idl : IDL source for QcDAL.dll
//

import "oaidl.idl";
import "ocidl.idl";

/////////////////////////////////////////////////////////////////////////////
// forward declarations we may need
/////////////////////////////////////////////////////////////////////////////

cpp_quote("struct _Connection;")

[
  uuid(AF86A5F1-2CBD-11D4-AC30-00A0244EB971),
  version(1.0),
  helpstring("QcDAL 1.0 Type Library")
]
library QCDALLib
{
  importlib("stdole32.tlb");
  importlib("stdole2.tlb");
  importlib("/program files/common files/system/ado/msado15.dll");

  interface IDbConnection;
  [
    object,
    uuid(AF86A5FE-2CBD-11D4-AC30-00A0244EB971),
    dual,
    helpstring("IContext Interface"),
    pointer_default(unique)
  ]
  interface IContext : IDispatch
  {
    [id(3), helpstring("method GetADOConnPtr")] 
      HRESULT GetADOConnPtr(
        [out, retval] _Connection** ppConnection);
  };
  .
  .
  .


Second COM DLL

This is the one that utilizes both the first COM DLL and ADO.

cpp_quote("struct _Connection;")
cpp_quote("struct IDAL;")

// ------------------------------------------------------------------------- //


[
  uuid(FFCBC525-5733-4B10-80A2-8C63079DF082),
  version(1.0),
  helpstring("QSE 1.0 Type Library")
]
library QSELib
{
  importlib("stdole32.tlb");
  importlib("stdole2.tlb");
  importlib("/program files/common files/system/ado/msado15.dll");
  import "/projects/c3/objects/qcdal/qcdal.idl";
  .
  .

Note that you again need to do the importlib of ADO. After that, you do the regular import of the first COM idl file. Now, wherever you need to use the first COM in you second COM dll, you need to import the msado15.dll before importing the first COM dll, since none of the msado types are in the first COM typelibrary. So, a typical .cpp (or possibly header) in the second COM dll would contain the lines:

  .
  .
  #import "/program files/common files/system/ado/msado15.dll" no_namespace rename("EOF", "adoEOF")
  #import "/projects/c3/objects/qcdal/qcdal.dll" no_namespace

Ok, this should fix it. Have fun!

Comment on this article

TOP