Wrapping around stdcall
Marcus Meissner
marcus at jet.franken.de
Tue Jul 5 14:30:43 CDT 2005
On Tue, Jul 05, 2005 at 07:42:23PM +0200, Maarten Lankhorst wrote:
> I have been trying to get some work done on a class returned by
> CreateTextServices, but the differences between windows' stdcall and
> linux' are giving me a few headaches. right now I've done it pretty much
> like this:
>
> /* These macros are taken from wine/dlls/msvcrt/cpp.c */
> #ifdef __i386__ /* thiscall functions are i386-specific */
>
> #define THISCALL(func) __thiscall_ ## func
> #define THISCALL_NAME(func) __ASM_NAME("__thiscall_" #func)
> #define DEFINE_THISCALL_WRAPPER(func) \
> extern void THISCALL(func)(); \
> __ASM_GLOBAL_FUNC(__thiscall_ ## func, \
> "popl %eax\n\t" \
> "pushl %ecx\n\t" \
> "pushl %eax\n\t" \
> "jmp " __ASM_NAME(#func) )
> #else /* __i386__ */
>
> #define THISCALL(func) func
> #define THISCALL_NAME(func) __ASM_NAME(#func)
> #define DEFINE_THISCALL_WRAPPER(func) /* nothing */
>
> #endif /* __i386__ */
> DEFINE_THISCALL_WRAPPER(fnTextSrv_TxSendMessage);
> static HRESULT __stdcall fnTextSrv_TxSendMessage(ITextServices *iface,
> UINT msg,
> WPARAM wparam,
> LPARAM lparam,
> LRESULT* plresult)
> { .... }
>
> static const ITextServicesVtbl textservices_Vtbl =
> {
> fnTextSrv_QueryInterface,
> fnTextSrv_AddRef,
> fnTextSrv_Release,
> THISCALL(fnTextSrv_TxSendMessage),
> ... };
>
> This works, however it is not clean, it gives me 2 compiler warnings:
> 1: fnTextServ_TxSendMessage defined but not used
You can mark it as used with a __GNUC__ ifdef... like this:
#ifdef __GNUC__
__attribute__((used))
#endif
static HRESULT __stdcall fnTextSrv_TxSendMessage(ITextServices *iface,
> 2: initialisation from incompatible pointer type (in the vtable)
Hmm, unclear. You would need to change the extern void THISCALL(func)(); to
be the correct prototype.
__typeof__() games might not work.
> I wonder how I can do this cleaner (Meaning no compiler warnings without
> ugly hacks). Also I would like to know how to call a function like
> __thiscall_fnTextSrv_TxSendMessage, because some methods I need are
> implemented in windows' stdcall. And I would like to know wether
> include/textserv.h needs to be adjusted now that I know they are not WINAPI.
Adding "thiscall" to gcc would perhaps help in the long run ... :/ Fun fun fun...
Ciao, Marcus
More information about the wine-devel
mailing list