C#/callbacks in C#
Expert: Srini Nagarajan - 4/2/2008
QuestionHello
I've read your article about callbacks. I've implemented it as you, but it crashes with "Attempted to read or write protected memory. This is often an indication that other memory is corrupt." exception.
this is how function I need to call is declared:
bool USB2CAN_Open(CAN_SPEED speed, bool CreateCommThreads , void (*error_function)(int err_code, const char * error_string), bool low_speed);
This is my code:
public unsafe delegate void funCallback(int err_code, char * error_string);
[DllImport("can.dll", CharSet = CharSet.Auto)]
public static extern unsafe bool USB2CAN_Open(CAN_SPEED speed, bool CreateCommThreads , funCallback callback, bool low_speed);
unsafe static void ErrorUSB2CAN_1(int error_code,char *text)
{
/*show error*/
}
/*
some code
*/
// this is how I call the function
funCallback fun = new funCallback(ErrorUSB2CAN_1);
bool back = USB2CAN_Open(CAN_SPEED.SPEED_10k, true, fun , false);
When I'm debugging, it crashes over the last line with the exception I mentioned before.
thank you for your answer
Mike
Answerhi
Looks like somewhere Memory leak deducted, you may want to check this url
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=3041566&SiteID=1
http://www.netnewsgroups.net/group/microsoft.public.dotnet.framework.aspnet/topi...
Thanks
-Srini