QT调用COM

8303阅读 2评论2011-12-27 sxcong
分类:C/C++

1 生成一个COM dll,例:
2 使用MFC测试成功。
3 使用QtCreater创建一个新工程
设置一下: .pro  
                 QT+= qaxcontainer qaxserver
                 CONFIG += qaxcontainer
4 增加一个按键,增加其点击事件。
5 代码
#include   //定义CLSID等
#include  //我们写的COM接口,由ATL Wizard生成的头文件
//QString 转 BSTR
static inline BSTR QStringToBSTR( const QString & str )
 {       return  SysAllocStringLen(( OLECHAR *) str .unicode(),   str .length());  } void MainWindow ::on_pushButton_clicked()
{
const CLSID CLSID_CGreet = { 0x1638ED3F , 0x43E1 , 0x11D6 ,{ 0x89 , 0xB2 , 0x00 , 0x01 , 0x03 , 0x02 , 0x15 , 0x8B }};        const   IID   IID_ICGreet   =   { 0x1638ED3E , 0x43E1 , 0x11D6 ,{ 0x89 , 0xB2 , 0x00 , 0x01 , 0x03 , 0x02 , 0x15 , 0x8B }}; QAxObject link ( QUuid ( CLSID_CGreet ).toString());
      ICGreet   *   psl   =   0 ;       link .queryInterface( IID_ICGreet ,   ( void **)& psl );       if   ( psl )       {          char *   mname   =   "test11111" ;          QString   bstresult ( mname );          char   ret [ 256 ];          BSTR   b   =  QStringToBSTR( ret );          psl -> SayHello (QStringToBSTR( bstresult ),& b );          QString   q_str (( QChar *) b ,  wcslen( b ));          QMessageBox ::information(NULL,   "Title" ,   q_str ,   QMessageBox :: Yes   |   QMessageBox :: No ,   QMessageBox :: Yes );          psl -> Release ();       }}  用法和MFC基本一样。


怎样上传代码呢?
上一篇:完整的SIP软电话工程实施过程
下一篇:libUV编译

文章评论