boost::bind 封装 COM 接口返回的 HANDLE
我有一个使用如下 COM 对象的 Visual Studio 2008 c++ 项目:
ISomeComInterface* foo;
HANDLE file = foo->CreateFile();
// file operations...
foo->CloseHandle( file );
我想使用 boost::shared_ptr
来封装返回的 HANDLE
的生命周期管理> 对象。例如:
ISomeComInterface* foo;
boost::shared_ptr< void > file( foo->CreateFile(),
boost::bind( &ISomeComInterface::CloseHandle, foo, _1 ) );
// file operations...
不幸的是,这不能编译:
1>Compiling...
1>Audit Tool.cpp
1>boost\bind\bind.hpp(69) : error C2825: 'F': must be a class or namespace when followed by '::'
1> boost\bind\bind_template.hpp(15) : see reference to class template instantiation 'boost::_bi::result_traits<R,F>' being compiled
1> with
1> [
1> R=boost::_bi::unspecified,
1> F=int (__stdcall ISomeComInterface::* )(HANDLE)
1> ]
1> Myapp.hpp(78) : see reference to class template instantiation 'boost::_bi::bind_t<R,F,L>' being compiled
1> with
1> [
1> R=boost::_bi::unspecified,
1> F=BOOL (__stdcall ISomeComInterface::* )(HANDLE),
1> L=boost::_bi::list2<boost::_bi::value<ISomeComInterface *>,boost::arg<1>>
1> ]
1>boost\bind\bind.hpp(69) : error C2039: 'result_type' : is not a member of '`global namespace''
1>boost\bind\bind.hpp(69) : error C2146: syntax error : missing ';' before identifier 'type'
1>boost\bind\bind.hpp(69) : error C2208: 'boost::_bi::type' : no members defined using this type
1>boost\bind\bind.hpp(69) : fatal error C1903: unable to recover from previous error(s); stopping compilation
我该怎么做才能获得我正在寻找的功能?
谢谢, 保罗·H
I have a Visual Studio 2008 c++ project that uses a COM object like this:
ISomeComInterface* foo;
HANDLE file = foo->CreateFile();
// file operations...
foo->CloseHandle( file );
I would like to use boost::shared_ptr<>
to encapsulate the lifetime management of the returned HANDLE
object. e.g:
ISomeComInterface* foo;
boost::shared_ptr< void > file( foo->CreateFile(),
boost::bind( &ISomeComInterface::CloseHandle, foo, _1 ) );
// file operations...
Unfortunately, this doesn't compile:
1>Compiling...
1>Audit Tool.cpp
1>boost\bind\bind.hpp(69) : error C2825: 'F': must be a class or namespace when followed by '::'
1> boost\bind\bind_template.hpp(15) : see reference to class template instantiation 'boost::_bi::result_traits<R,F>' being compiled
1> with
1> [
1> R=boost::_bi::unspecified,
1> F=int (__stdcall ISomeComInterface::* )(HANDLE)
1> ]
1> Myapp.hpp(78) : see reference to class template instantiation 'boost::_bi::bind_t<R,F,L>' being compiled
1> with
1> [
1> R=boost::_bi::unspecified,
1> F=BOOL (__stdcall ISomeComInterface::* )(HANDLE),
1> L=boost::_bi::list2<boost::_bi::value<ISomeComInterface *>,boost::arg<1>>
1> ]
1>boost\bind\bind.hpp(69) : error C2039: 'result_type' : is not a member of '`global namespace''
1>boost\bind\bind.hpp(69) : error C2146: syntax error : missing ';' before identifier 'type'
1>boost\bind\bind.hpp(69) : error C2208: 'boost::_bi::type' : no members defined using this type
1>boost\bind\bind.hpp(69) : fatal error C1903: unable to recover from previous error(s); stopping compilation
What can I do to get the functionality I'm looking for?
Thanks,
PaulH
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Eric 回答了问题
#define BOOST_MEM_FN_ENABLE_STDCALL
htttp://www.boost.org/doc/libs/1_45_0/libs/bind/bind.html#Q_com
Eric answered the question
#define BOOST_MEM_FN_ENABLE_STDCALL
htttp://www.boost.org/doc/libs/1_45_0/libs/bind/bind.html#Q_com