Boost.Function __stdcall, __fastcall, etc

Started by
4 comments, last by GreenElephant 13 years, 12 months ago
I inject my dll into the process space of a game, and Im trying to create a function pointer to a function defined inside the games dll. If I use normal function pointers, it will work:
typedef void(__stdcall *FunctionPtr_t)(void);
FunctionPtr_t myFuncPtr = &SomeFunc
But if I try to use boost::function, I get compile time errors:
boost::function<void __stdcall(void)> myBoostFuncPtr;
error C2079: 'myBoostFuncPtr' uses undefined class 'boost::function<Signature>'
If I remove the __stdcall it compiles just fine... Any ideas on how to get this to work?
Advertisement
There are some macros to try enabling.

Boost: bind.hpp documentation - "__stdcall", "__cdecl", "__fastcall", and "pascal" Support

"I can't believe I'm defending logic to a turing machine." - Kent Woolworth [Other Space]

Thank you for the reply, I have tried defining BOOST_BIND_ENABLE_STDCALL before including the boost header files, but I still get the same compile error.
Try doing it in your project files. I don't know why they imply doing it in a source is workable: In order to get it to work with #defines, you would have to make sure it's before the FIRST #include <boost/bind.hpp> in the entire Translation Unit, which is tantamount to #defining it before EVERY #include <boost/bind.hpp> in your ENTIRE PROJECT/solution/etc.
You shouldn't need to make __stdcall part of the boost::function<> type; it should be able to adapt function pointers regardless of the calling convention.
Quote:Original post by SiCrane
You shouldn't need to make __stdcall part of the boost::function<> type; it should be able to adapt function pointers regardless of the calling convention.

When I don't specify a calling convention, and I compile a Debug build, I get the following runtime error:
Quote:Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function with one calling convention with a function pointer declared with a different calling convention.

I have the option of Aborting, Retrying, and Ignoring.
When I click Retry, it works..

If I compile a Release build instead of a Debug build, it works just fine.
I wonder if it is still having a problem, but is silent about it because its not a Debug build...

This topic is closed to new replies.

Advertisement