[WinAPI] Problem with an interface...

Frits van Bommel fvbommel at REMwOVExCAPSs.nl
Thu Nov 22 06:12:29 PST 2007


Sascha Katzner wrote:
> I have a Windows function (GetTechniqueByName), which returns a pointer 
> to an interface (which in D results to a simple interface, because in D 
> interfaces are allready reference types).
> 
> If I try subsequently to call a function from this interface something 
> very strange happens, the call results in the very next function from 
> the interface declaration being called. For example if I call 
> "technique.IsValid()" D calls GetDesc(), which results in an access 
> violation.
> 
> This behavior appears only to happen with interfaces which are NOT 
> derived from IUnknown.

Interfaces are only compatible with non-D code if they're COM interfaces 
(i.e. derive from IUnknown). Other interfaces are D(-compiler)-specific 
and thus incompatible with non-D code. This also means that "interfaces" 
returned from non-D code that don't derive from IUnknown can't be 
declared using 'interface'. However, if you know how to call their 
functions from C you can still use the C-like way to access them (using 
structs and explicitly accessing the vtable, for example).

Non-COM interfaces use a D-specific vtable layout (causing you to call a 
different function) and calling convention (but you may've gotten 
"lucky" with two no-argument functions).



More information about the Digitalmars-d mailing list