You are here:

C#/callbacks in C#

Advertisement


Question
Hello
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

Answer
hi

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

C#

All Answers


Answers by Expert:


Ask Experts

Volunteer


Srini Nagarajan

Expertise

can answer any kind of questions in ASP.NET, C#, VB.NET, ASP, SharePoint 2007, Coldfusion, Powerbuilder 7.00 / 8.00, JAVA servlets, MS SQL 2000 / MSSQL7, Sybase

Experience

Contact me if you need any custom development on ASP.NET, ASP, Coldfusion, Powerbuilder

©2012 About.com, a part of The New York Times Company. All rights reserved.