Win32 headers: Problem with COM interface indirection levels

Carlos Santander csantander619 at gmail.com
Wed Aug 8 12:11:56 PDT 2007


Michael Butscher escribió:
> 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

I don't use Windows, but I haven't heard of anyone having this problem before. 
Can you test that with a simpler case? Remember that there's a ComInterface (or 
something like that) in std.c.windows.com (I think) which gets special treatment 
by the compiler. Maybe the compiler performs some magic there in order to get 
everything working fine.

Also, maybe this question is better suited in the Bindings project Dsource forum?

-- 
Carlos Santander Bernal



More information about the Digitalmars-d mailing list