结构体的定义
[StructLayout(LayoutKind.Sequential, Size = 64, CharSet = CharSet.Ansi), Serializable]
public struct UDPDeviceINFO
{
[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 10)]
public byte[] tpe; //设备类型
[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 16)]
public byte[] sio; //设备号
[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 4)]
public byte[] IP; //IP
}
int cnt = 0;
int workStationCount = 254;
int size = Marshal.SizeOf(typeof(Message.UDPDeviceINFO));
IntPtr infosIntptr = Marshal.AllocHGlobal(size * workStationCount);
Message.UDPDeviceINFO[] devinfo = new Message.UDPDeviceINFO[workStationCount];
int ret = Message.CKT_UdpSearchDev(infosIntptr, ref cnt);
for (int I = 0; I < cnt; I++)
{
IntPtr ptr = (IntPtr)((UInt32)infosIntptr + I * size);
devinfo[I] = (Message.UDPDeviceINFO)Marshal.PtrToStructure(ptr, typeof(Message.UDPDeviceINFO));
}
Marshal.FreeHGlobal(infosIntptr);