C# 调用c++ 实例
时间:2011-01-18 来源:clound
接口文档如下:
c++中的Struct 如下:
typedef struct { int deviceID; //阅读器逻辑ID char address[20]; //IP地址或串口;如"COM1","10.86.10.56" int status; //0-未链接;1-已链接,未初始化;2-已链接,已初始化 int style; //0-网络客户端;1-网络服务端;2-串口 } ReaderItem; typedef struct { int length; unsigned char tagData[2048]; //标签长度1byte(lenth字)+标签epc码(lenth*2)byte+标签长度1byte+标签epc码 } InventoryResult;
c#的类如下:
public class RFIDBaseManage { [DllImport("xxx.dll")] public static extern int Connect(string dev, ref int devid); [DllImport("xxx.dll")] public static extern int Disconnect(int devid); [DllImport("xxx.dll", EntryPoint = "GetReaders")] public static extern int GetReaders(ref ReaderItem item,int maxCount,ref int count); } public class RFIDInfoManage { [DllImport("xxx.dll", EntryPoint = "EPC1G2_Inventory")] public static extern int EPC1G2_Inventory(int DeviceID, short antennalID, ref InventoryResult result); } [StructLayout(LayoutKind.Sequential)] public struct ReaderItem { public int deviceID; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 20)] public string address; //IP地址或串口;如"COM1","10.86.10.56" public int status; public int style; } [StructLayout(LayoutKind.Sequential)] public struct InventoryResult { public int length; [MarshalAs(UnmanagedType.ByValArray, SizeConst = 2048)] public byte[] tagData; }
另外,也可以参考这几篇文章:
http://hi.baidu.com/yun0216/blog/item/37a463106b575ffec3ce7913.html
对于Byte[]的处理 可以参考
相关阅读 更多 +