PInvoke with a CString
问题 I'm trying to use P/Invoke to call functions in an unmanaged C++ DLL from C#. The C++ DLL uses CString 's as function parameters and returns, such as CString AFX_EXT_API GetUserName(CString& userID) Unfortunately, the C++ is legacy code that I cannot change to use the more universal LPSTR (or even char * ). Is there any way to marshal the CString into a .NET compatible object? Or somehow decorate a .NET char[] to be marshaled to a CString? 回答1: You can't create a CString in managed code. So