boost::bind 封装 COM 接口返回的 HANDLE

发布于 2024-10-05 05:53:17 字数 1810 浏览 7 评论 0原文

我有一个使用如下 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

悲凉≈ 2024-10-12 05:53:17

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文