0

I'm using a c++ dll in a Unity3D project. It`s important to use CharSet = CharSet.Ansi

 [DllImport("Exchange3D", EntryPoint = "GetElementValue", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
 private static extern double fnGetElementValue(int nType, int nNumber, string strPointName);

strPointName is sent to the dll. But the dll receives it in an incorrect format in the Unity Project!

But I created a C# Console Application with the same code and all is working!

Any ideas?

Jin Park
  • 13
  • 3
  • I think this can help you: http://stackoverflow.com/questions/20752001/passing-strings-from-c-sharp-to-c-dll-and-back-minimal-example – ThomasSquall Sep 03 '15 at 06:54

1 Answers1

0

A string needs to be const char* on the c++ side, and not std::string. You might also consider defining the c++ functiona as a ansi-c function instead since that can be easier to map in c#.

Have a look at this piece of information to get an idea of how to map a simple function that works with a string.

https://msdn.microsoft.com/en-us/library/system.runtime.interopservices.callingconvention(v=vs.110).aspx
Chris
  • 498
  • 5
  • 16