1、结构体的处理
C++中:
typedef struct _DEVICE_LOCATION
{
ULONG DeviceId;
//Device ID
ULONG VendorId;
//Vendor ID
ULONG SubsystemId;
//Subsystem ID
ULONG RevisionId;
//Revision ID
CHAR
DeviceCode[16];
//采集卡型号
} DEVICE_LOCATION, *PDEVICE_LOCATION;
UINT WINAPI lvGetDeviceInfo(PDEVICE_LOCATION Device, RETURN_CODE *rc);//RETURN_CODE是一个枚举
转换到C#中:
[StructLayout(LayoutKind.Sequential,CharSet=CharSet.Ansi)]
public struct DeviceLocation
{
public uint DeviceId;
//Device ID
public uint VendorId;
//Vendor ID
public uint SubsystemId;
//Subsystem ID
public uint RevisionId;
//Revision ID
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)]
public string DeviceCode;
//采集卡型号
}
这样就可以方便的编出C#的函数原型
[DllImport("lvpci.dll")]
public static extern uint lvGetDeviceInfo(ref DeviceLocation Device,ref ReturnCode rc);