Marshall结构与字符串数组C#

时间:2016-03-04 00:56:29

标签: c# arrays string serialization marshalling

我正在尝试Marshall一个包含整数,字符串和字符串数组的结构。我在序列化字符串数组时遇到问题。每次我收到“FatalExecutionEngine Error”。我需要序列化我的结构,以便使用套接字API通过TCP发送它。

我找到了几个例子,但我真的不理解它们:/任何人都可以解释一下这个过程是如何工作的?

 [StructLayout(LayoutKind.Sequential)]
    public struct MESSAGE
    {
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 101)]
        public string gameID;
        public int msgID;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 101)]
        public string param1;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 101)]
        public string param2;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 101)]
        public string param3;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 101)]
        public string param4;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 101)]
        public string param5;
        [MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.LPTStr, SizeConst = 222)]
        public string[] clientsArray;
    }

0 个答案:

没有答案