Why can't I return a char* string from C++ to C# in a Release build?

后端 未结 5 949
梦如初夏
梦如初夏 2021-01-31 10:07

I\'m attempting to call the following trivial C function from C#:

SIMPLEDLL_API const char* ReturnString()
{
    return \"Returning a static string!\";
}
         


        
5条回答
  •  轮回少年
    2021-01-31 10:50

    Or maybe try to use

    [DllImport("SimpleDll")]
    public static extern IntPtr ReturnString();
    

    and in your calling code, use the Marshal Class

    string ret = System.Runtime.InteropServices.Marshal.PtrToStringAnsi(PInvoke.ReturnString());
    

提交回复
热议问题