Delegate not working...
-
Hey guys, I'm trying to get a callback function to work from my unmanaged C++ dll. Everytime I run my program I get System.NullReferenceException saying "Object reference not set to an instance of an object." in mscorlib. This error is thrown when the runtime tries to execute the callback function in my unmanaged C++ DLL. What I'm trying to do is real simple and straightforward: namespace ProtocolDll { __delegate void MY_CALLBACK(); [DllImport("test.dll")] extern "C" void UnmanagedFunc(MY_CALLBACK __gc* myCallback); public __gc class Wrapper { public: void myCallback() { MY_CALLBACK* cb = new MY_CALLBACK(this,&Wrapper::CallMePlease); UnmanagedFunc(cb); // Call the unmanaged dll function } void CallMePlease() { Int32 i=0; i=i+1; // I put a breakpoint here but it never makes it }; } ************************************ Here is my unmanaged C++ dll code: typedef void (*MY_CALLBACK)(); EXPORT void UnmanagedFunc(MY_CALLBACK* pfnCallback); void UnmanagedFunc(MY_CALLBACK* pfnCallback) { (*pfnCallback)(); } Any idea what I am doing wrong? Thanks for any help... this is my last issue with this unmanaged dllimport stuff... this code is a bear to write. david