Win32 headers: Problem with COM interface indirection levels

Michael Butscher mbutscher at gmx.de
Wed Aug 8 05:04:42 PDT 2007


Hi,

there seems to be a rather fundamental error in the translation of COM 
interfaces by the Win32 bindings project:

The C++ headers defines an interface as a class (more precisely a 
struct) with some virtual methods. This means, an instance of the 
interface is the actual object data, mainly containing a pointer to the 
vtable.

In D, an interface is a pointer to the object data which contains in 
turn the pointer to the vtable.

Because of the different level of indirection e.g. the IShellFolder 
interface in D is in fact equivalent to the LPSHELLFOLDER type in C++.


I think there are two possible solutions:

1. Modify parameter types of all functions using the interface, e.g. 
translate C++ definition:

  HRESULT SHGetDesktopFolder(LPSHELLFOLDER*);


to:
  
  HRESULT SHGetDesktopFolder(LPSHELLFOLDER);

or:

  HRESULT SHGetDesktopFolder(IShellFolder*);




2. Rewrite the definitions of the LP... types as aliases of the 
interfaces (I would prefer that), e.g.

C++:

  typedef IShellFolder *LPSHELLFOLDER;


to D:

  alias IShellFolder LPSHELLFOLDER;




I think this is important so the decision should be documented in the 
Translation instructions.



Michael



More information about the Digitalmars-d mailing list