tobias-loew / windows_thunks

Thunks for Windows (x86 and x64) - or how to pass non-static member-functions as Windows-Callbacks
Boost Software License 1.0
6 stars 3 forks source link

static_assert failed: 'thunked function is not a member function' #5

Open sherkat69 opened 6 months ago

sherkat69 commented 6 months ago

the function I'm trying to thunk is a WINAPI. in x64, it compiles fine but in x86 the static_assert fails:

// ensure it's not a variadic function
static_assert(boost::function_types::is_member_function_pointer<call_type, boost::function_types::thiscall_cc>::value, "thunked function is not a member function");

I'm using VS2022 (v143) and c++17

tobias-loew commented 6 months ago

Can you give a short example that reproduces the error?

sherkat69 commented 6 months ago
LONG WINAPI PExHandler(_EXCEPTION_POINTERS* ExceptionInfo)
{

}

lunaticpp::thunk<&PExHandler> m_thunk_PExHandler{ this };

i think, NOT SURE, that in previous versions of "windows_thunks" i could compile it.

ps: i also had another issue. maybe that fix has something to help with this issue.

tobias-loew commented 6 months ago

Just remove the "WINAPI" macro and everything should work. The non-static callback function must not be __stdcall (that's what WINAPI does), but a "normal" thiscall function.

For x86-64 this problem does not exist, as there is only one calling convention used by msvc (fastcall) cf. https://en.wikipedia.org/wiki/X86_calling_conventions (vectorcall must be specified explicitly)

sherkat69 commented 6 months ago

wont this affect the mechanism of exception handling when i pass this function to "AddVectoredExceptionHandler"? my whole goal was using a WINAPI in a class as a member function.

tobias-loew commented 6 months ago

The synthesized static function returned by func() will have the stdcall (aka WINAPI, aka CALLBACK) calling convention. But the non-static member function must not have it.

(When you comment out the static_assert from above and run the code with WINAPI in debug mode you get a stack corruption exception)