I've made this to call unmanaged function from C code. pCallback is a function pointer so on the managed side is a delegate.
[DllImport("MyDLL.dll")]
public static extern Result SetCallback(
IntPtr handle,
Delegate pCallback,
CallbackType Type);
Now I am setting
private delegate void pfnCallback(uint PromptID, ttsEventType evt, IntPtr lData);
private pfnCallback cb = new pfnCallback(cback);
public Form1()
{
(...)
Wrapper.SetCallback(handle, cb, IntPtr.Zero, CallBackType.DEFAULT);
(...)
public static void cback(uint PromptID, ttsEventType evt, IntPtr lData)
{ }
}
When debugging, I see that it runs the cback function once, and then I get an Exception with no data, just saying "An unhandled win32 exception occurred in WindowsApp2.vshost.exe[4372]. I don't understand what's wrong. Can anyone help me?