Hook C# with C++ event

A

Ali

Hello all,

I have created a DLL using C++. I use this dll in a C# project. How can I
make C# listen to an event that is raised inside one of the functions of the
dll?

for exaxmple:
C++:

void MyCPPFunc()
{
HANDLE hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
SetEvent(hEvent);
}

----------

C#:
//Need to listen to hEvent and do some stuff when it is signaled??

[DllImport("MyDll.dll")]
static extern void MyCPPFunc();

Please help!
 
A

Ali

Well, the most obvious approach would be to use p/invoke to call
WaitForSingleObject() on the handle.

Thanks for your reply, Pete!

OK, but how can I pass the handle to C#? I means how can I p/invoke it?

Don't I need to do this first before I can call WaitForSingleObject() in C#?

Thank you!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top