On Sun, Apr 25, 2010 at 11:34 PM, Steven Watanabe <watanabesj@gmail.com> wrote:
AMDG


Brian Rowlett wrote:
I am writing a DLL that gets injected into another process, and creates pointers to the target processes functions. The target process uses all 3 calling conventions, __stdcall, __fastcall and __cdecl.
 I have created a class whos constructor gets the address of the function, and passes it to the base class boost::function:
 
   template <typename _Signature, enum LibraryId _LibraryId, int _Offset>
   class FunctionPointer: protected OffsetPointer, public
   boost::function<_Signature>
   {
   public:
       FunctionPointer(void)
       :
   boost::function<_Signature>( OffsetPointer::_getOffset(_LibraryId,
   _Offset )
       { return; }
   };

 I instantiate this with:
 
   FunctionPointer<return_type__stdcall( argument_types ), LibraryId,
   Offset> Function;

   FunctionPointer<return_type __cdecl( argument_types ), LibraryId,
   Offset> Function;

 Whatever calling convention Visual Studio is setup to use (__cdecl by default), works just fine. But trying to instantiate it with another calling convention gives the following error:
 
   Error 1 error C2504: 'boost::function<Signature>' : base class
   undefined

 It seems weird that it would work for some calling conventions, and not others..
 Any ideas?

Don't try to specify a calling convention for Boost.Function.
return_type __cdecl(argument_types) works because it
is equivalent to return_type(argument_types) which is
what Boost.Function accepts.  A boost::function should
be able to store function pointers that use /any/ calling
convention.

In Christ,
Steven Watanabe

_______________________________________________
Boost-users mailing list
Boost-users@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users

When I don't specify a calling convention, and I compile a Debug build, I get the following runtime error:
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...
 
--
+ Brian J. Rowlett