C++ interface vs D and com

Adam Sansier via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jul 12 19:41:22 PDT 2016


On Wednesday, 13 July 2016 at 02:25:35 UTC, Jesse Phillips wrote:
> On Tuesday, 12 July 2016 at 15:09:26 UTC, Adam Sansier wrote:
>> So, com throughs me a interface ptr and I need to map it to an 
>> interface. When I do, I get an access violation.
>>
>> I have an (com) ptr and an interface. How do I link them up so 
>> I can call the functions?
>>
>> I marked the interface extern(C++) so it's a C++ style 
>> interface.
>>  The first field of a COM object is a pointer to its vtable.  
>> This is still true in extern(C++) D, right? The calling 
>> convention is thiscall.
>>
>> https://dlang.org/spec/cpp_interface.html
>
> I'm not the best person to answer your questions here, but if 
> you're working with COM you do not want to declare them as 
> extern(C++). D supported COM long before it did direct C++ 
> interfacing.
>
> You can look at how Juno interfaces with Windows COM objects:
>
> https://github.com/JesseKPhillips/Juno-Windows-Class-Library/blob/master/source/juno/xml/msxml.d#L226
>
> You'll notice that it inherits from IDispatch instead of 
> IUnknown, Juno defines that interface.
>
> https://github.com/JesseKPhillips/Juno-Windows-Class-Library/blob/master/source/juno/com/core.d#L2063
>
> Juno tries to make it easier to write and interface with COM, 
> but I've only been keeping it compiling and haven't gotten to 
> writing my own stuff (I've run into issues with manifest files 
> an such). It would be awesome if you found it useful and could 
> improve on the experience.
>
> https://github.com/JesseKPhillips/Juno-Windows-Class-Library/wiki


I think you would have to explain to me why it would be worth 
switching. At least in my case it is already working and seems to 
be much easier than a quick casual glance at juno. I don't need a 
full blown COM lib at this point though and maybe it only works 
for my use case(Where CoCreateInstance returns the interface ptr 
directly and no need to query).

I think extern(C++) is necessary because of the calling 
convention. I could be wrong. extern(Windows) definitely doesn't 
work. Why the methods I'm using might seem a bit hackish, they 
are working and is rather simple(a few lines of code), it might 
not be robust though.

Maybe you could write up a little more on the juno 
readme.markdown file to explain it's purpose and capabilities.

It seems like it provides server capabilities, which at don't 
need at the moment(maybe later), and seems quite large. My com 
code is basically about 10 lines total + the interface.

If you can convince me to try it out, I might... but doing com 
isn't my primary goal here and I seem to have finished up what I 
was trying to achieve(my use case is probably relatively simple 
though). Last thing I want to do is get bogged down in this 
stuff, which feels clumsy and not well documented(Both the D and 
C sides)







More information about the Digitalmars-d-learn mailing list