Proe二次开发中,vc调用vb编写的com

#include <io.h>
#include <Stdio.h>
#import "E://vs//Projects//comtest1//ClassLibrary1//bin//Debug//ClassLibrary1.tlb" no_namespace //引入com组件

HWND ProWnd;
int newbuttonac();
uiCmdAccessState filter1(uiCmdAccessMode access_mode);
extern "C" int user_initialize()
{
ProFileName msgfilebuff;
ProStringToWstring(msgfilebuff,"KEmsg.txt");

uiCmdCmdId newbuttonid;
ProMenubarMenuAdd("New Menu","New-M-L","Help",PRO_B_TRUE,msgfilebuff);//添加一个新的菜单。定义的名字为“New Menu”,而实际显示的名字为在text文档中定义的“New-M-L”的值。定义菜单的位置在“Help”的右方。参考的text文件为msgfilebuff。
ProCmdActionAdd("New-Menu-AC",(uiCmdCmdActFn)newbuttonac,uiCmdPrioDefault,filter1,PRO_B_FALSE,PRO_B_FALSE,&newbuttonid);
ProMenubarmenuPushbuttonAdd("New Menu","New Push Button","N-B-L","N-B-H",NULL,PRO_B_TRUE,newbuttonid,msgfilebuff); //在New Menu菜单下添加一个新的按钮。

ProWnd=GetActiveWindow();
SetTimer(ProWnd,1,1000,TimerProc);
return 0;

}

extern "C" void user_terminate()
{
}

VOID CALLBACK TimerProc(HWND hWnd,UINT uMsg,UINT idEvent,DWORD dwTime)
{
if(_access("D://PKTest//TK_F4.ini",0)==0) return;
if(_access("D://PKTest//TK_BU4.ini",0)==0)
{
rename("D://PKTest//TK_BU4.ini","D://PKTest//TK_F4.ini");
newbuttonac();
}
}

int newbuttonac()
{
CoInitialize(NULL);//COM Pool初始化
CLSID clsid,iid;//定义classid和interfaceid
_bstr_t pRetr;//定义com函数回传值类型
_comtest2 *pRet=NULL;//定义COM Interface类型
HRESULT hr;//定义COM Instance回传类型
CLSIDFromString(L"{34d6550c-2c89-466f-99f4-7ad8b9261f99}",&clsid);//取出classid
CLSIDFromString(L"{b68d60a9-7ecb-4cdf-8fe6-e5ea1dd17c56}",&iid);//取出interfaceid
hr=CoCreateInstance(clsid,NULL,CLSCTX_ALL,iid,(VOID**)&pRet);//COM Interface接口建立
  if(SUCCEEDED(hr))
{
    // COM 函数执行与回传值
    pRetr=pRet->comUI() ;
    // 回传值型别转换
    strcpy_s(rtn, (char*)pRetr);
    // 字串比对
     /* if(strcmp(rtn,"ok")==0)
      {
         ProMessageDisplay(msgfile,"Form_start_ok");
       }
       else
       {
          MessageBox(NULL,rtn,"Error",MB_OK);
        }*/
        // COM 接口释放
        pRet->Release();
        }
        else
        {
          MessageBox(NULL,"Error","Error",MB_OK);
         }
        // COM Pool 结束
        CoUninitialize();
        return 0;
}

发布了39 篇原创文章 · 获赞 3 · 访问量 9万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章