DLLs with COM interface

Jarrett Billingsley kb3ctd2 at yahoo.com
Wed Dec 5 05:25:39 PST 2007


"Henrik" <zodiachus at gmail.com> wrote in message 
news:fj617q$15qk$1 at digitalmars.com...
> Hello!
>
>
> I was reading up on http://www.digitalmars.com/d/dll.html#com regarding 
> how to call DLLs with a COM interface, since this is exactly what I am 
> struggling with.
>
> I'm trying to interface with proprietary DLLs that I know expose COM 
> interfaces. Fortunately, I have the documentation for them so I know 
> exactly what methods they expose.
>
> There is, for example trtCom.dll, which exposes a trtComMgr class, which 
> has a method AboutBox(). I thought I'd start with calling that, since it 
> takes no arguments and returns nothing.
>
> Now, it said in the article mentioned above that COM objects and D 
> interfaces are virtually the same thing, so I tried this:
>
> extern(Windows)
> {
> interface MbtComMgr
> {
> void AboutBox();
>
> }
> }
>
> But that wasn't very popular with the D compiler. It simply said:
> Error: need 'this' to access member AboutBox
>
> What would be the proper way of accessing a COM DLL?

COM interfaces have to inherit from IUnknown.  IUnknown is "magic" and the 
compiler treats it specially.

Furthermore, I think you should put the extern(Windows) on the inside of the 
interface, as I don't think putting it on the outside will affect the 
calling conventions of the things on the inside.  (Putting it on the outside 
won't do much of anything, actually, except maybe change the name mangling 
of the interface.)

So you'll have:

import std.c.windows.com;

interface MbtComMgr : IUnknown
{
extern(Windows):
    void AboutBox();
}

:) 




More information about the Digitalmars-d-learn mailing list