Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
sherkat69 opened this issue May 23, 2024 · 5 comments
Open

Comments

@sherkat69
Copy link

sherkat69 commented May 23, 2024

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
Copy link
Owner

Can you give a short example that reproduces the error?

@sherkat69
Copy link
Author

sherkat69 commented May 25, 2024

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
Copy link
Owner

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
Copy link
Author

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
Copy link
Owner

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants