0

When I try to import the function

extern __declspec(dllexport)  void SomeNativeFunction(const std::string param1, const std::string param2);  

defined and declared in SomeNative.Dll into a .NET console application using

class Program
{
        [DllImport("SomeNative", CallingConvention = CallingConvention.Cdecl)]
        extern static void SomeNativeFuntion(string param1, string param2);
        static void Main(string[] args)
        {   
            StartEventHandling("param1", "param2");
        }
}

I get the error

System.AccessViolationException' occurred in ManagedS7DosEventManagerClient.dll Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

Which is probably an indication, that I need to marshal the parameters correctly.

This overview of default marshalings for strings unfortunately doesn't say anything about marshaling of standard library strings.

Oblomov
  • 8,953
  • 22
  • 60
  • 106

0 Answers0