Plea to fix winelib COM vtable bug

Matthew Bloch matthew at
Sat Nov 2 08:59:45 CST 2002

This is a summary of my recent probs with Winelib in the hope that someone who 
knows the COM stuff can fix them quickly, because hacking through the jungle 
of include files and definitions is hard work 

In short, I've built the latest wine cvs with the ICOM_MSVTABLE_COMPAT flag 
set in include/wine/obj_base.h, so each vtable has two dummy words at the 
start for g++'s benefit.

I then added these statements to the start of my WinMain to cause a segfault:

    IDirectDraw* dd;
    DirectDrawCreate(0, &dd, NULL;)

and for good measure, wrapped the call to IDirectDraw7_QueryInterface in 
DDRAW_Create (which is where the segfault occurs) in ddraw/main.c with these 
two warnings:

    WARN("about to call IDirectDraw7_QueryInterface vtbl size = %d\n", 

    hr = IDirectDraw7_QueryInterface(pDD, iid, lplpDD);

    WARN("called IDirectDraw7_QueryInterface\n");

and when running the program, the trace clearly shows that the Release entry 
point is being called instead, and crashing, though the vtable is the 
expected size (5 entry points, plus 2 dummy dwords):

    warn:ddraw:DDRAW_Create about to call IDirectDraw7_QueryInterface vtbl 
size = 28
    warn:ddraw:DDRAW_Create offset is 12271064
    trace:ddraw:Main_DirectDraw_Release (0x403a7c70)->() decrementing from 1.
    warn:ddraw:Main_DirectDraw_Release doing final release

Looking at the pre-processor output from compiling ddraw/main.c, I can see 
that IDirectDraw7Vtbl type has the two extra words grafted onto the front, as 
it should:

struct IDirectDraw7Vtbl { 
  long dummyRTTI1; 
  long dummyRTTI2; 
  HRESULT (__attribute__((__stdcall__)) *QueryInterface)(IDirectDraw7* me,
    const IID* const a, LPVOID* b); 
  ULONG (__attribute__((__stdcall__)) *AddRef)(IDirectDraw7* me); 
  ULONG (__attribute__((__stdcall__)) *Release)(IDirectDraw7* me);

The problem seems to be that the call is offset not just by two table entries, 
but four.  Somewhere in that jungle of macros, the "vtable base adjustment" 
of +2 is being applied twice, I'm sure of it.  But I'm buggered if I can find 
out where this is happening; I'm still looking but it's slow progress and I 
believe it's a winelib bug.

Any suggestions on how to fix it would be welcome.  cheers,

Matthew Bloch         Bytemark Computer Consulting Limited
                                  tel. +44 (0) 8707 455026

More information about the wine-devel mailing list