How do I properly return a char * from an Unmanaged DLL to C#?

后端 未结 5 841
生来不讨喜
生来不讨喜 2021-01-06 08:57

Function signature:

char * errMessage(int err);

My code:

[DllImport(\"api.dll\")]       
internal static extern char[] errMessage(int err);         


        
5条回答
  •  醉梦人生
    2021-01-06 09:37

    See this question. To summary, the function should return an IntPtr and you have to use Marshal.PtrToString* to convert it to a managed String object.

提交回复
热议问题