首页 文章

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

提问于
浏览
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

我该怎么做才能获得我正在寻找的功能?

谢谢,PaulH

1 回答

  • 0

    埃里克回答了这个问题

    #define BOOST_MEM_FN_ENABLE_STDCALL

    HTTTP://www.boost.org/doc/libs/1_45_0/libs/bind/bind.html#Q_com

相关问题