www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How to COM interfaces work

reply StarGrazer <Stary Night.com> writes:
I have a COM interface that is dynamically created using invoke 
and such.

One of the functions returns an interface. It is just a value of 
IUnknown or whatever.

If I use it as a pointer in to the the D interface equivalent, it 
crashes as the value is not pointing to anything valid.

What do these values represent? I tried to use QueryInterface 
from the class who's function provides the "COM interface" but it 
returns interface not supported.

So, I have one dynamic COM interface that I initialize properly 
and can call it's functions and all the ones I tested work fine. 
Some of those functions returns interfaces. If I try to call the 
functions on those interfaces, the app crashes.

How to I get the interfaces the return values represent? Or for 
that matter, the functions that ask for an interface, what do I 
pass? Passing or using the generated D interfaces does not work.
Mar 18
next sibling parent reply evilrat <evilrat666 gmail.com> writes:
On Sunday, 19 March 2017 at 02:04:53 UTC, StarGrazer wrote:
 I have a COM interface that is dynamically created using invoke 
 and such.

 One of the functions returns an interface. It is just a value 
 of IUnknown or whatever.

 If I use it as a pointer in to the the D interface equivalent, 
 it crashes as the value is not pointing to anything valid.

 What do these values represent? I tried to use QueryInterface 
 from the class who's function provides the "COM interface" but 
 it returns interface not supported.

 So, I have one dynamic COM interface that I initialize properly 
 and can call it's functions and all the ones I tested work 
 fine. Some of those functions returns interfaces. If I try to 
 call the functions on those interfaces, the app crashes.

 How to I get the interfaces the return values represent? Or for 
 that matter, the functions that ask for an interface, what do I 
 pass? Passing or using the generated D interfaces does not work.
I'm sorry, but probably you should read something like this[1] first, this tech(COM) is beyond D, so you must understand how it works before trying it in D. [1] https://www.codeproject.com/Articles/633/Introduction-to-COM-What-It-Is-and-How-to-Use-It
Mar 18
next sibling parent StarGrazer <Stary Night.com> writes:
On Sunday, 19 March 2017 at 02:45:48 UTC, evilrat wrote:
 On Sunday, 19 March 2017 at 02:04:53 UTC, StarGrazer wrote:
 I have a COM interface that is dynamically created using 
 invoke and such.

 One of the functions returns an interface. It is just a value 
 of IUnknown or whatever.

 If I use it as a pointer in to the the D interface equivalent, 
 it crashes as the value is not pointing to anything valid.

 What do these values represent? I tried to use QueryInterface 
 from the class who's function provides the "COM interface" but 
 it returns interface not supported.

 So, I have one dynamic COM interface that I initialize 
 properly and can call it's functions and all the ones I tested 
 work fine. Some of those functions returns interfaces. If I 
 try to call the functions on those interfaces, the app crashes.

 How to I get the interfaces the return values represent? Or 
 for that matter, the functions that ask for an interface, what 
 do I pass? Passing or using the generated D interfaces does 
 not work.
I'm sorry, but probably you should read something like this[1] first, this tech(COM) is beyond D, so you must understand how it works before trying it in D. [1] https://www.codeproject.com/Articles/633/Introduction-to-COM-What-It-Is-and-How-to-Use-It
Please don't be condescending to me. You have no idea how much I know or don't know. I already have most of the COM stuff working in D so I do know something. I'm not a complete idiot like you are presupposing. I am asking a very simple question and if you don't know the answer then may you should read the article to know if I know enough or not.
Mar 18
prev sibling parent StarGrazer <Stary Night.com> writes:
On Sunday, 19 March 2017 at 02:45:48 UTC, evilrat wrote:
 On Sunday, 19 March 2017 at 02:04:53 UTC, StarGrazer wrote:
 I have a COM interface that is dynamically created using 
 invoke and such.

 One of the functions returns an interface. It is just a value 
 of IUnknown or whatever.

 If I use it as a pointer in to the the D interface equivalent, 
 it crashes as the value is not pointing to anything valid.

 What do these values represent? I tried to use QueryInterface 
 from the class who's function provides the "COM interface" but 
 it returns interface not supported.

 So, I have one dynamic COM interface that I initialize 
 properly and can call it's functions and all the ones I tested 
 work fine. Some of those functions returns interfaces. If I 
 try to call the functions on those interfaces, the app crashes.

 How to I get the interfaces the return values represent? Or 
 for that matter, the functions that ask for an interface, what 
 do I pass? Passing or using the generated D interfaces does 
 not work.
I'm sorry, but probably you should read something like this[1] first, this tech(COM) is beyond D, so you must understand how it works before trying it in D. [1] https://www.codeproject.com/Articles/633/Introduction-to-COM-What-It-Is-and-How-to-Use-It
Reading that tells me nothing about how to get a dynamic COM interface of a dynamic COM interface... but I guess you knew that, didn't you? I'm sorry, but you are an ____.
Mar 18
prev sibling parent reply Adam D. Ruppe <destructionator gmail.com> writes:
On Sunday, 19 March 2017 at 02:04:53 UTC, StarGrazer wrote:
 If I use it as a pointer in to the the D interface equivalent, 
 it crashes as the value is not pointing to anything valid.
What's the code look like? What interface too?
Mar 18
parent reply StarGrazer <Stary Night.com> writes:
On Sunday, 19 March 2017 at 03:10:02 UTC, Adam D. Ruppe wrote:
 On Sunday, 19 March 2017 at 02:04:53 UTC, StarGrazer wrote:
 If I use it as a pointer in to the the D interface equivalent, 
 it crashes as the value is not pointing to anything valid.
What's the code look like? What interface too?
It's very complicated. I use a lot of reflection to extract the interface functions and build a d class from them. Like I said, the initial dynamic COM interface works fine. I can call it's functions so all that code is irrelevant. The problem is, some of those functions return COM interfaces(they inherit IDispatch interfaces in D). The interfaces are generated from idl2d. So they are just standard d interfaces that only mock up the COM interfaces. But it is probably not a D issue. IDispatch.Invoke returns a COM VARIANT type with the return type(which is an IDispatch interface according to idl2d). HRESULT CoCreateInstance( _In_ REFCLSID rclsid, _In_ LPUNKNOWN pUnkOuter, _In_ DWORD dwClsContext, _In_ REFIID riid, _Out_ LPVOID *ppv ); https://msdn.microsoft.com/en-us/library/windows/desktop/ms686615(v=vs.85).aspx I assume I'll have to use that to create the COM of COM by passing the returned value from invoke in to the pUnkOuter and do all that. I haven't tried it yet but will when I get a chance. I'd just like to get some conformation on the process so at least I know I'm headed in the right direction. The project is pretty complex and most of the stuff is done in compile time code.
Mar 18
parent evilrat <evilrat666 gmail.com> writes:
On Sunday, 19 March 2017 at 03:27:28 UTC, StarGrazer wrote:
 I'd just like to get some conformation on the process so at 
 least I know I'm headed in the right direction. The project is 
 pretty complex and most of the stuff is done in compile time 
 code.
What debug shows? If CoCreateInstance and calling other interfaces is working for you, then it could be really D issue, because not much people really use this stuff. Also it could be wrong vptr table (method order issue) generated from reflection, or it could be D vptr issues related to com (can you try interface instead of class?), or D compiler bugs or wrong ABI(try different compilers/versions) That's probably it, not sure if there is other potential quirks out there...
Mar 18