简体   繁体   English

tr1 :: function WINAPI

[英]tr1::function WINAPI

How can I use tr1::function with WINAPI calling convention ? 如何在WINAPI调用约定中使用tr1 :: function? (at least in windows). (至少在windows中)。 I can use visual c++ 9 SP1 TR1 or BOOST's one... 我可以使用visual c ++ 9 SP1 TR1或BOOST的一个......

typedef void (WINAPI *GetNativeSystemInfoPtr)(LPSYSTEM_INFO);
HMODULE h = LoadLibrary (_T("Kernel32.dll"));
GetNativeSystemInfoPtr fp = (GetNativeSystemInfoPtr) GetProcAddress (h,"GetNativeSystemInfo");
SYSTEM_INFO info;
fp(&info); //works!

// This doesn't compile 
function< void WINAPI (LPSYSTEM_INFO) > fb = (GetNativeSystemInfoPtr) GetProcAddress (h,"GetNativeSystemInfo");

This compiles: 这编译:

#include <boost/function.hpp>
#include <windows.h>


int main(void)
{
    typedef void (WINAPI *GetNativeSystemInfoPtr)(LPSYSTEM_INFO);
    HMODULE h = LoadLibrary (("Kernel32.dll"));
    GetNativeSystemInfoPtr fp = (GetNativeSystemInfoPtr) GetProcAddress (h,"GetNativeSystemInfo");
    SYSTEM_INFO info;
    fp(&info); //works!

    boost::function< void (LPSYSTEM_INFO) > fb = (GetNativeSystemInfoPtr) GetProcAddress (h,"GetNativeSystemInfo");
    SYSTEM_INFO info2;
    fb(&info2);


    return 0;
}

and the contents on "info" is the same that the one of "info2", so it seems to work. 并且“info”中的内容与“info2”中的内容相同,所以它似乎有效。

My understanding is that the parameter used to instantiate a boost::function is the signature of its operator(). 我的理解是用于实例化boost :: function的参数是其operator()的签名。 It is not strictly related to the signature of the function of function object that it wraps. 它与包装的函数对象的功能的签名没有严格的关系。 Otherwise, its benefits would be lost, since boost::function's utility is precisely to be able to wrap anything that is callable behind a uniform interface, regardless of the details of the final target's type. 否则,它的好处将会丢失,因为boost :: function的实用程序正是能够包装在统一接口后面可调用的任何东西,而不管最终目标类型的细节。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM