المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : System.AccessViolationException



C# Programming
06-19-2009, 09:17 AM
Hi All,

I am trying to do something like this:

I have a C++ dll, this dll has a function which accepts filename(String) ,dataTobewritten(char array) and the length of the char array(long). The function then creates a file with the specified name and writes the data to it.

I am trying to call this function from C# code using P/Invoke.
The problem is that whenever the function is invoked it throws an exception as follows:

"Attempted to read or write protected memory. This is often an indication that other memory is corrupt."

I have tried the following options:

1) Setting the application as a trusted application in application properties.
2) Checked the C++ code so as to make sure there are no memory leaks due to bad pointers or missing 'Dealloc' statements.
3) Verififed that the signatures match exactly.

I am at my wits end, as there seems to be no solution for this.

Can anyone please throw some light on any other options?
It would be of really great help.

P.S: I am using VS 2008 express edition (if that makes a difference, as I am aware that MS had released a patch for the same problem for its 2.0 version.)

Thanks in advance.
Siddy