Win32 headers: Problem with COM interface indirection levels
Don Clugston
dac at nospam.com.au
Thu Aug 9 05:20:15 PDT 2007
Michael Butscher wrote:
> 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 you're right (and I'm probably responsible for most of it). It's a
straightforward but fundamental error. Essentially, there's already a * in the
definition of a D class. The second way is how it should be.
Should be straightforward to fix with a simple bit of grepping.
More information about the Digitalmars-d
mailing list