I connect the C ++ library to the C # project, the library is fully working. Guide to connecting took here .
[DllImport("C:\\Users\\Zaki\\Desktop\\SetsGen.dll", CallingConvention = CallingConvention.Cdecl)] public static extern string GetSets(string ids, int power); public void DllSub(string param) { try { string myAns = GetSets(param, 3); string[] tokens = myAns.Split('/'); foreach (var token in tokens) { Console.WriteLine(token); } } catch (Exception ex) { Console.WriteLine(ex.Message); } } The native signature of the GetSets function in Dll looks like this:
std::string GetSets(std::string ids, int power) I get an exception when accessing the ported GetSets function:
An unhandled exception of type 'System.AccessViolationException' occurred in Test.exe
Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
What could be the reasons and how to fix it?