Boost logo

Boost Users :

Subject: Re: [Boost-users] Boost.Function __stdcall, __fastcall, etc
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2010-04-26 00:34:19


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 list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net