lpstr

Calling C++ function with LPStr return value from C#

ぐ巨炮叔叔 提交于 2019-12-24 20:53:50
问题 I have a C++ dll in 64-Bit, which contains a function that returns an LPStr . I would like to call this function in C#. The function declaration looks like this: __declspec(dllexport) LPSTR __stdcall function(int16_t error_code); In my C# code I have tried the following: [DllImport(@"<PathToInterface.dll>", EntryPoint = "function")] [return: MarshalAs(UnmanagedType.LPStr)] public static extern string function(Int16 error_code); And then in the program: string ErrorMessage = ""; ErrorMessage =