Hi,
I want to use a dll in my VC++ project. The Dll, have some functions and some events. how do i handle events of dll in my project?
name of event is: TestEvent(int i , string msg) when i call test() function of Dll, the event will be called.
The Dll is written by C# whit this code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace My_Managed
{
using System.Collections;
public delegate void TestDelegate(int i , string msg);
public class Class1
{
public event TestDelegate TestEvent;
public virtual void OnTestEvent(int i , string msg)
{
if (TestEvent != null)
OnTestEvent(i, msg);
}
}
}
public interface MY_Interface
{
bool test();
};
public class MY_Class : MY_Interface
{
MY_Managed.Class1 c = new MY_Managed.Class1();
public MY_Class()
{
}
public bool test()
{
c.OnTestEvent(99, "ok Test");
return true;
}
}
I register the Dll and use .tlb of it in my VC++ Project:
#import "..\..\MY_Managed.tlb" raw_interfaces_only
using namespace MY_Managed;
void CVCTestDlg::OnBnClickedButton1()
{
try
{
MY_InterfacePtr pos(__uuidof(MY_Class));
VARIANT_BOOL b;
pos->test(&b);
}
catch(CException* ex)
{
WCHAR wch[1024];
ex->GetErrorMessage(wch, 1024);
AfxMessageBox(wch);
}
}
Now, how do I Handle 'TestEvent' in VC++ Project? how do I hook it? Please help me.