日期:2014-05-18 浏览次数:21046 次
typedef struct _COMMPORTCONFIG { DWORD BaudRate; // baud rate DWORD ByteSize; // number of bits/byte, 4-8 DWORD Parity; // 0-4=no,odd,even,mark,space DWORD StopBits; // 0,1,2 = 1, 1.5, 2 DWORD fOutxCtsFlow; // CTS Flow Control } COMMPORTCONFIG; C/C++: BOOL MetrocomInitCommunication(int i_port, COMMPORTCONFIG * p_config);
DLL 传递结构 (见代码) BOOL PtInRect(const RECT *lprc, POINT pt); using System.Runtime.InteropServices; [StructLayout(LayoutKind.Sequential)] public struct Point { public int x; public int y; } [StructLayout(LayoutKind.Explicit)] public struct Rect { [FieldOffset(0)] public int left; [FieldOffset(4)] public int top; [FieldOffset(8)] public int right; [FieldOffset(12)] public int bottom; } Class XXXX { [DllImport("User32.dll")] public static extern bool PtInRect(ref Rect r, Point p); }
------解决方案--------------------
public struct COMMPORTCONFIG
{
int BaudRate; // baud rate
int ByteSize; // number of bits/byte, 4-8
int Parity; // 0-4=no,odd,even,mark,space
int StopBits; // 0,1,2 = 1, 1.5, 2
int fOutxCtsFlow; // CTS Flow Control
}
[DllImport("DLL文件名")]
public static extern bool MetrocomInitCommunication(int i_port, ref COMMPORTCONFIG p_config);
------解决方案--------------------
[DllImport("你DLL名称")] public static extern bool MetrocomInitCommunication(int i_port, ref COMMPORTCONFIG p_config); [StructLayout(LayoutKind.Sequential)] public struct _COMMPORTCONFIG { int BaudRate; // baud rate int ByteSize; // number of bits/byte, 4-8 int Parity; // 0-4=no,odd,even,mark,space int StopBits; // 0,1,2 = 1, 1.5, 2 int fOutxCtsFlow; // CTS Flow Control } int i_port; COMMPORTCONFIG p_config=new COMMPORTCONFIG (); MetrocomInitCommunication(i_port, ref p_config);
------解决方案--------------------