Urgent help needed! Raising events!

  • Thread starter Thread starter Catherine Jones
  • Start date Start date
C

Catherine Jones

Dear All
Please help me in the following issue:
how to raise an event from an unmanaged class to a
managed class.
Both classes are in C++ and there should not be any static methods involved
in this implementation.
ie. the event source is an unmanaged class and event receiver should be a
managed class.
Also the event receiver method should not be static.
Thank you very much for your understanding.
 
Catherine,

I assume that by "raising an event" you mean invoking a delegate? The
following code shows how you can invoke a delegate in unmanaged code:

------------------------------------------------------------------------
#using <mscorlib.dll>

using namespace System;

__delegate void TestEventHandler();

class UnmanagedClass {
public:
void doSomething(TestEventHandler *testEventHandler);
};

void UnmanagedClass::doSomething(TestEventHandler *testEventHandler) {
testEventHandler->Invoke();
}

__gc class ManagedClass {
public private:
void testEventOccurred() {
Console::WriteLine(S"It happened!");
}
};

int _tmain()
{
UnmanagedClass unmanagedClass;
ManagedClass *managedClass = new ManagedClass();
unmanagedClass.doSomething(new TestEventHandler(managedClass,
ManagedClass::testEventOccurred));
return 0;
}
 
Thanx Bart, I got an idea from your code.
Thanx a lot for your time and understanding!
 
Back
Top