I am trying to write a dll in C++ that a C# app can register a callback with. There are plenty of examples on the web, but none that I can get to work. They compile and run, and don't give any errors, but just don't work.
The C++ code
The C# code
The code in the C# Main function hits the registerCallBack line, and if I F10 it, the IDE just unloads. No error, nothing.
This code looks good to me from the tutorials I have been reading online, can anyone spot the glaring error?
The C++ code
Code:
extern "C" _declspec(dllexport) void registerCallBack(void (_stdcall *func)()){
//Just call the callback once for now
func();
return;
}
Code:
public delegate void CallBackDelegate();
[DllImport("MyDll"]
public static extern void registerCallBack(CallBackDelegate del);
static void myCallBack()
{
Console.WriteLine("Callback fired!");
return;
}
static void Main(string[] args)
{
CallBackDelegate del = new CallBackDelegate(myCallBack);
registerCallBack(del);
Console.WriteLine("Callback registered");
}
This code looks good to me from the tutorials I have been reading online, can anyone spot the glaring error?

Comment