Marshaling structure to single line of string
问题 [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] public class Comarea { [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 1)] public string status; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 5)] public string operationName; } public static void StringToObject(string buffer, out Comarea comarea) { IntPtr pBuf = Marshal.StringToBSTR(buffer); comarea = (Comarea)Marshal.PtrToStructure(pBuf, typeof(Comarea)); } I can create object from single line of string but I can not do