我想复制一个64的char数组,它是一个方法的参数到一个结构成员,我使用我的结构作为Buffer,结构中的成员也被定义为64的char数组,但是它被编组。我尝试使用不同的方法,但每次复制此数组时,它显示的值是00 00 00 .......还有另一种方法来复制它。
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)]
protected struct TCommandParam
{
public int IValue;
[MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.U1, SizeConst = 4096)]
public char[] SValue;
[MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.U1, SizeConst = 64)]
public char[] FrameFD;
[MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.U1, SizeConst = 16)]
public char[] CRCProfile;
public int TCanTime;
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)]
protected struct TCommandBuffer
{
public int Command;
[MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.Struct, SizeConst = 10)]
public TCommandParam[] Param;
public int ReturnValue;
public TCommandBuffer(int tsize)
{
this.Command = 0;
this.Param = new TCommandParam[tsize];
this.ReturnValue = 0;
}
}
这是我要复制的功能。
public int CAN_TransmitSingleFD(int canNo, int iD, char[] frameFD)
{
this.ReadBuffer();
this.CANDIAG_CommandBufferInit();
this.buff.Param[1].IValue = canNo;
this.buff.Param[2].IValue = iD;
this.buff.Param[3].FrameFD = frameFD;
this.CANDIAG_Client_SendCommand(809);
this.WriteBuffer();
return this.CANDIAG_CommandBufferExit();
}