0

my c# part

[DllImport("asdf.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
    unsafe extern public static int CompareDB(string[] filename);

Below is c++ part

extern "C" __declspec(dllexport)int CompareDB(char** name)
{             
    CString filename="It is already assigned in previous code"    
    strcpy(name[1], (const char *)fileName); 
}

Error is related with attempting to read or write protected memory.

Somebody help me please.

2
  • How do you know that name[1] will be large enough to contain the string? Do you have some convention that all strings are allocated to be a certain size? Commented Nov 7, 2014 at 7:17
  • Can you change the calling sequence of CompareDB? If so, the solution suggested here might apply. Commented Nov 7, 2014 at 7:33

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.