Wrapping around stdcall

Felix Nawothnig felix.nawothnig at t-online.de
Tue Jul 5 19:02:36 CDT 2005


Maarten Lankhorst wrote:
> It looks evil, and those functions are not exactly what I want, because 
> I need them in a vtable, which requires them to be something like 
> HRESULT ... fnTextServ_blah(ITextServices *iface, args), I could recast 
> those functions, but that is not exactly a 'clean' solution, adding 
> 'thiscall' to gcc would definitely help a lot. Until gcc supports 
> thiscall, I think it would be easier to just fix the macro's I already 
> have and set attribute 'used' to avoid compiler warnings. But I still 
> wonder what I have to do to call a 'thiscall' function, since I probably 
> need it in ITextHost.

With those (evil) macros you could do:

#define CALL_THISCALL0(name,this) __thiscall_#name(0,0,this)
#define CALL_THISCALL1(name,this,p1) __thiscall_#name(0,0,this,p1)

If you wanna use the same technique as used in MSVCRT you would do 
something like:

#define STDCALL(func) __stdcall_ ## func
#define STDCALL_NAME(func) __ASM_NAME("__stdcall_" #func)
#define DEFINE_STDCALL_WRAPPER(func) \
     extern void STDCALL(func)(); \
     __ASM_GLOBAL_FUNC(__stdcall_ ## func, \
                       "popl %eax\n\t" \
                       "popl %ecx\n\t" \
                       "pushl %eax\n\t" \
                       "jmp " __ASM_NAME(#func) )

Now you can do:

void WINAPI foo(int a, int b);

DEFINE_STDCALL_WRAPPER(foo);

int bar()
{
     __stdcall_foo(1,2,3);
}

Thinking up better macro-names is left as an exercise for the reader. :)

Felix



More information about the wine-devel mailing list