When I try to import c++ dll in unity on win10, I got an error:
ExecutionEngineException: String conversion error: Illegal byte sequence encounted in the input.
Why? And I have tried the unity stable version 2019 and 2021.
c++:
const char* say_hello(const char* text) {
std::string s = "Hello, " + std::string(text);
return s.c_str();
}
c#:
[DllImport(libraryName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
public static extern IntPtr say_hello([MarshalAs(UnmanagedType.LPStr)] string text);
Debug.Log(Marshal.PtrToStringAnsi(say_hello("world")));