ACDTP_RECEIVE_HEAD ac=new ACDTP_RECEIVE_HEAD();
ac.PktLength=10000000;
ac.PktType=1;
byte[] Bytes=new byte[System.Runtime.InteropServices.Marshal.SizeOf(ac)];
byte[] byte1=BitConverter.GetBytes(ac.PktLength);
byte[] byte2=BitConverter.GetBytes(ac.PktType);
byte1.CopyTo(Bytes,0);
byte2.CopyTo(Bytes,byte1.Length-1);
ac.PktLength=10000000;
ac.PktType=1;
byte[] Bytes=new byte[System.Runtime.InteropServices.Marshal.SizeOf(ac)];
byte[] byte1=BitConverter.GetBytes(ac.PktLength);
byte[] byte2=BitConverter.GetBytes(ac.PktType);
byte1.CopyTo(Bytes,0);
byte2.CopyTo(Bytes,byte1.Length-1);
PttoStruct是将非托管结构转换为托管结构,大致应该这样吧public unsafe static ACDTP_RECEIVE_HEAD* getPtr()
{
return (ACDTP_RECEIVE_HEAD*)0; //allocate memory in free heep from here
}
public static Fun()
{
unsafe
{
object o=Marshal.PtrToStructure((System.IntPtr)Form1.getPtr(),typeof(ACDTP_RECEIVE_HEAD));
}
}
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconoutarrayofstructssample.asp
谢谢上面的兄弟