零、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 .