Ken H

Ken H

  • NA
  • 646
  • 355.1k

Access Violation Exception in c#

Aug 2 2014 12:43 PM
hi friend,
       When I call the C++ dll function, the following error occurred:
   Error Message=Attempts to read from or write to protected memory. This is often an indication that other memory is corrupt.
 
C++ codes:
string test(string s[]){
string t="";
 
for(int i=0;i<2;i++){
   t+=s[i];
}
 
return t;
}
 
C# codes:
class Program
{    
     [DllImport("safeTest.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern string test(string[] s);
static void Main(string[] args)
{
string[] city = { "London ", "San Francisco " };
string temp = test(city);
Console.WriteLine(temp);
Console.ReadKey();
}
}
 
Thanks. 
 
 

Answers (3)