日期:2014-05-18 浏览次数:21174 次
typedef struct _CANFRAME { UCHAR mFrame[10]; }CANFRAME,*PCANFRAME;
[DllImport("你的DLL路径")] public static extern int Pci6621_Send(int mDev, int mPort, byte[] pSendFrame);
------解决方案--------------------
需要一个CANFRAME结构的指针(引用)
[StructLayout(LayoutKind.Sequential)] public struct CANFRAME { [MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.U1, SizeConst = 10)] public byte[] mFrame; } public class LibWrap { [DllImport("MyDll.dll")] public static extern bool Pci6621_Send([In] Int32 mDev, [In] Int32 mPort, ref CANFRAME pSendFrame); } static void Main() { CANFRAME sendFrame = new CANFRAME(); sendFrame.mFrame = new byte[10]; //sendFrame.mFrame[0] = 0x01; //... bool bSuccess = LibWrap.Pci6621_Send(0, 0, ref sendFrame); }
------解决方案--------------------
楼上办法可行,给你一个更全面的:
http://blog.csdn.net/sdl2005lyx/article/details/6801113
------解决方案--------------------
ref 结构体名
结构体自己定义