Hi, I could use some help in setting a C# callback function that an
external unmanaged dll will call on a event. Using a delegate and use
the external callback set function doesn't work.
The carbage collector says hello here (-;
I have pasted some code below, any help is greatly appreciated!
//Bart
public delegate void HercEventCallbackHandler(HercAction dwAction, uint
dwValue, uint userInstance);
[DllImport("HERC.dll")]
public static extern bool
HERC_EventCallbackSet(HercEventCallbackHandler HERCPROC_DeckA,
HercEventCallbackHandler HERCPROC_DeckB, uint userInstance);
public void HercEventCallbackHandlerA(HercAction dwAction, uint
dwValue, uint userInstance)
{
//process the event
}
public Form1()
{
HERC_EventCallbackSet(HercEventCallbackHandlerA,
HercEventCallbackHandlerB, 69);
}
Exception info:
A callback was made on a garbage collected delegate of type
'Hertest!Hertest.Form1+HercEventCallbackHandler::I nvoke'. This may
cause application crashes, corruption and data loss. When passing
delegates to unmanaged code, they must be kept alive by the managed
application until it is guaranteed that they will never be called.