C++ interface vs D and com
Adam Sansier via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Jul 13 13:36:23 PDT 2016
On Wednesday, 13 July 2016 at 20:02:50 UTC, Jesse Phillips wrote:
> On Wednesday, 13 July 2016 at 02:41:22 UTC, Adam Sansier wrote:
>> 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)
>
> Juno is definitely of more value if you're trying to access
> standard Windows COM objects, that way you don't have to write
> the interface definitions yourself.
>
> You'd mentioned that you got it work with a hack and there
> should be a better way, Juno might be that better way.
>
> It looks to me like your extern(C++) is needed because you're
> trying to shove the pointer from coCreateInstance into a D
> class. With COM you don't work with concrete classes, only
> interfaces. Code below is not tested and only from limited
> knowledge.
>
> IMYCASIO cASIO : IUnknown
> {
> void func1(char *name);
> void func2(int);
> }
>
> //...
> IMYCASIO obj;
> CoCreateInstance(..., cast(void**) &obj);
>
> obj.func1("me");
>
> The only other thing I can think is, if you are obtaining an
> object that defines static methods, those aren't supported by
> COM. COM only works on virtual functions and you're probably
> just hacking memory address space to get at those functions.
But juno wouldn't work with this then? Regardless if the "COM"
interface I'm using is truly com as defined by some yet unknown
standard, it is what I have to work with.
I was able to simply the code. I required marking only those
functions of the interface as extern(C++), everything else is
normal and simple. I was able to simply cast the ptr to the
interface and it worked. The thing I tried in the first 5 mins
that didn't, probably because I used extern(Windows) like some
fools say *HAVE& to be used which wasted 2 days of my life(ok,
only a few hours each day but still ;) chasing that rabbit,
actually did work.
So, the point of this thread is simply to state for those in the
future that such discrepancies do exist and are hard to figure
out because there is little info on them.
This already thwarted one person:
http://forum.dlang.org/thread/iovu2e$2d3d$1@digitalmars.com
So this is a 10 year problem: 2006-2011-2016. Funny how it
happens in 5 year increments. Was Kagamin in on it? Does he have
some vested interest in people not getting this stuff to work?
Luckily I don't listen to fools, and luckily extern(C++) was
implemented since then and we now have a solution.
More information about the Digitalmars-d-learn
mailing list