用VB写了个ActiveX DLL,自定义了一个事件,用VC调用这个DLL,编译能够通过,就是调用时那个时间不触发啊,代码如下:
VB的代码如下:
建了一个窗体:放定时器,代码:
Public Filename As String
Public Event FileFound()Private Sub Timer1_Timer()
    RaiseEvent FileFound '不管找不找得到,触发
    If Dir(Filename) <> "" Then
    RaiseEvent FileFound
    End If
    Timer1.Interval = 0
End Sub还有一个类:代码如下:
Dim WithEvents objFileCheck As Form1
Dim con As New ADODB.Connection
Dim cmd As New ADODB.Command
Public Event FileFound(Filename As String)
Private Sub Class_Initialize()
    Set objFileCheck = New Form1
    con.Open "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=True;Data Source=sms.mdb"
    cmd.ActiveConnection = con
End SubPublic Function MonitorFile(Filename As String)
    objFileCheck.Filename = Filename
    objFileCheck.Timer1.Interval = 60000
End FunctionPrivate Sub Class_Terminate()
    con.Close
    Set cmd = Nothing
    Set con = Nothing
End SubPrivate Sub objFileCheck_FileFound()
    Dim strData As String
    strData = "data"
    cmd.CommandText = "insert into comdata (timm,datt) values ('" + (Format(Date, "YYYY-MM-DD ")) + Str((Time)) + "','" + (strData) + "')"
      cmd.Execute    RaiseEvent FileFound(objFileCheck.Filename)
End Sub然后生成 testevent.dll
在VC中采用选择Automation->From a type Libray ,加上这个DLL
调用如下:
void CTestdlleventDlg::OnButton1() 
{
// TODO: Add your control notification handler code here
_Class1 ct;
BSTR bb = ::SysAllocString(L"Readme.txt");
if(ct.CreateDispatch("testevent.Class1"))
{
AfxMessageBox("装载成功!");
}else{
AfxMessageBox("装载不成功!");
}

ct.MonitorFile(&bb);
}
执行后就是不触发那个时间,什么原因啊?