How to invoke active dll written by VB using VC - VC如何調用VB寫的Active Dll - 詳解

零、VB Dll:prjCOMWriteNTLog.clsMain 代碼,此程序只有一個Class
 
 Option Explicit

 Public Function WriteNTLog(ByVal strMsg As String)
         
     With App
      
         .StartLogging "c:/log.log", LogModeConstants.vbLogToNT
        
         .LogEvent strMsg, LogEventTypeConstants.vbLogEventTypeInformation
        
     End With
         
 End Function
 
一、在:CWinApp::InitInstance 函數中用AfxOleInit初始化 COM
 
 if (!AfxOleInit())
 {
  AfxMessageBox("AfxOleInit Failed!");
  return FALSE;
 }
 
 
二、用 #Import 引入你所要調用的 Dll
 
 #import "G:/C++ Projects/prjADOTest/res/prjCOMWriteNTLog.dll" no_namespace
 
 //Notice:這句話輸入完畢後,VC就會在:程序生成目錄中(Debug/Release)自動產生兩個文件:
 //  prjCOMWriteNTLog.tlh
 //  prjCOMWriteNTLog.tli

 

三、定義、創建:你要調用的Dll中的對象(Class)
 
 _clsMainPtr clsWriteLog;

 clsWriteLog.CreateInstance(__uuidof(clsMain));

 

四、使用 你要調用的Dll中的對象中的函數

 

 clsWriteLog->WriteNTLog("Jackiessssssssssssssssss");

 

五、It need the import dll support when the vc program runing .

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章