tr1::函数WINAPI
如何将 tr1::function 与 WINAPI 调用约定一起使用? (至少在 Windows 中)。我可以使用 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");
How can I use tr1::function with WINAPI calling convention ? (at least in windows). I can use visual c++ 9 SP1 TR1 or BOOST's one...
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");
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编译:
“info”上的内容与“info2”上的内容相同,所以它似乎有效。
我的理解是,用于实例化 boost::function 的参数是其operator()的签名。它与它包装的函数对象的函数签名没有严格关系。否则,它的好处就会消失,因为 boost::function 的实用性正是能够将任何可调用的东西包装在统一的接口后面,而不管最终目标类型的细节如何。
This compiles:
and the contents on "info" is the same that the one of "info2", so it seems to work.
My understanding is that the parameter used to instantiate a boost::function is the signature of its 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.