Accessing COM Objects

thedeemon via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Jun 16 20:14:42 PDT 2016


On Wednesday, 15 June 2016 at 21:06:01 UTC, Joerg Joergonson 
wrote:
> Ok, I've tried things like uncommenting
>
> 	Document Open(BSTR Document, VARIANT As, VARIANT 
> AsSmartObject);
> 	void Load(BSTR Document);
>
> 	/*[id(0x70537673)]*/ BSTR get_ScriptingVersion();
>   /*[id(0x70464D4D)]*/ double get_FreeMemory();
>   /*[id(0x76657273)]*/ BSTR get_Version();
> and everything crashes with bad reference.
>...
> My thinking is that CoCreateinstance is suppose to give us a 
> pointer to the interface so we can use it, if all this stuff is 
> crashing does that mean the interface is invalid or not being 
> assigned properly or is there far more to it than this?

First of all, you can't just comment/uncomment parts of COM 
interface descriptions. Each COM interface has some specific 
layout of its functions, and if you list them in wrong order or 
skip some of them the virtual methods table gets completely 
screwed up, so you think you call one method but end up calling 
another, because you intended to call method #12 and instead 
called method #4. COM interface definitions in D must match their 
definitions in IDL exactly. One omission of a method, one mistake 
in its type, and you're fucked.


More information about the Digitalmars-d-learn mailing list