Skip to main content
GameDev.net gamedev.net
🔒 Locked

Boost.Function __stdcall, __fastcall, etc

Started by GreenElephant Apr 25, 2010 at 11:00 AM 4 replies 3.6k views
Original Post
GreenElephant
GreenElephant
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?
GreenElephant
GreenElephant
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.
MaulingMonkey
MaulingMonkey
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 in the entire Translation Unit, which is tantamount to #defining it before EVERY #include in your ENTIRE PROJECT/solution/etc.
SiCrane
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.
GreenElephant
GreenElephant
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...

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.