DLLs with COM interface

Jascha Wetzel firstname at mainia.de
Wed Dec 5 04:12:10 PST 2007


Henrik wrote:
> But that wasn't very popular with the D compiler. It simply said:
> Error: need 'this' to access member AboutBox

the interface is just an abstract type, you'll always need an object 
that you access as such an interface. that object needs to be an 
instance of some class that implements the interface.
usually the DLL would expose a C-style function that returns such an object.
for standard COM, the DLL exposes DllGetClassObject that returns a class 
factory object, that can instantiate all COM objects contained in the 
DLL. the class factory object (that implements IClassFactory) has a 
CreateInstance method, that will give you object pointer for a requested 
interface.
for more details, [1] is a good place to start. i also recommend the 
book Essential COM by Don Box.

> The article said that "The sample code includes an example COM client 
> program and server DLL." What sample code is it talking about exactly? I 
> looked under C:\dmd\samples\d\mydll but found nothing that looks like an 
> example on this.

you can look at my code for "seatd for scite" at [2], that plugs code 
navigation functionality into the scite editor using com objects. the 
relevant code is in src/scite/seatd_scite.dll and src/scite/scite_ext.d
i'm not following COM completely here, i.e. i'm not implementing 
IClassFactory and the method that returns the object is not called 
DllGetClassObject, but it's basically COM and it covers your problem as 
well.

[1] http://en.wikipedia.org/wiki/Component_object_model
[2] http://seatd.mainia.de/


More information about the Digitalmars-d-learn mailing list