<div class="gmail_quote">On Sun, Apr 25, 2010 at 11:34 PM, Steven Watanabe <span dir="ltr">&lt;<a href="mailto:watanabesj@gmail.com">watanabesj@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
AMDG<div><div></div><div class="h5"><br>
<br>
Brian Rowlett wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
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.<br>
 I have created a class whos constructor gets the address of the function, and passes it to the base class boost::function:<br>
 <br>
    template &lt;typename _Signature, enum LibraryId _LibraryId, int _Offset&gt;<br>
    class FunctionPointer: protected OffsetPointer, public<br>
    boost::function&lt;_Signature&gt;<br>
    {<br>
    public:<br>
        FunctionPointer(void)<br>
        :<br>
    boost::function&lt;_Signature&gt;( OffsetPointer::_getOffset(_LibraryId,<br>
    _Offset )<br>
        { return; }<br>
    };<br>
<br>
 I instantiate this with:<br>
 <br>
    FunctionPointer&lt;return_type__stdcall( argument_types ), LibraryId,<br>
    Offset&gt; Function;<br>
<br>
    FunctionPointer&lt;return_type __cdecl( argument_types ), LibraryId,<br>
    Offset&gt; Function;<br>
<br>
 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:<br>
 <br>
    Error 1 error C2504: &#39;boost::function&lt;Signature&gt;&#39; : base class<br>
    undefined<br>
<br>
 It seems weird that it would work for some calling conventions, and not others..<br>
 Any ideas?<br>
</blockquote>
<br></div></div>
Don&#39;t try to specify a calling convention for Boost.Function.<br>
return_type __cdecl(argument_types) works because it<br>
is equivalent to return_type(argument_types) which is<br>
what Boost.Function accepts.  A boost::function should<br>
be able to store function pointers that use /any/ calling<br>
convention.<br>
<br>
In Christ,<br>
Steven Watanabe<br>
<br>
_______________________________________________<br>
Boost-users mailing list<br>
<a href="mailto:Boost-users@lists.boost.org" target="_blank">Boost-users@lists.boost.org</a><br>
<a href="http://listarchives.boost.org/mailman/listinfo.cgi/boost-users" target="_blank">http://listarchives.boost.org/mailman/listinfo.cgi/boost-users</a><br>
</blockquote></div><br>When I don&#39;t specify a calling convention, and I compile a Debug build, I get the following runtime error:<br><blockquote style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;" class="gmail_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.<br>
</blockquote><div>I have the option of Aborting, Retrying, and Ignoring.<br>When I click Retry, it works..<br></div><div><br>If I compile a Release build instead of a Debug build, it works just fine.<br>I wonder if it is still having a problem, but is silent about it because its not a Debug build...<br>
 </div>-- <br>+ Brian J. Rowlett<br>
<div style="visibility: hidden; display: inline;" id="avg_ls_inline_popup"></div><style type="text/css">#avg_ls_inline_popup {  position:absolute;  z-index:9999;  padding: 0px 0px;  margin-left: 0px;  margin-top: 0px;  width: 240px;  overflow: hidden;  word-wrap: break-word;  color: black;  font-size: 10px;  text-align: left;  line-height: 13px;}</style>

