我正在尝试使用机器的非托管DLL,其功能如下。
int SetTimeouts ( DWORD dwTxTimeout, DWORD dwRxTimeout)
int ListDevices ( DWORD *pArg1, char *pArg2, DWORD dwFlags)
int SetDescription (char *pDescription)
int OpenDevice (int iDeviceType, char* pData, int iDataType)
int GetReturnCode (int iCode, WORD *pCode, char *pData)
int OpenDevice (int iDeviceType, char* pData, int iDataType)
int GetVersion ( BYTE pm, BYTE *pRxData, DWORD *nRxSize )
int Read ( BYTE pm, BYTE *pRxData, DWORD *nRxSize )
int Write ( BYTE pm, BYTE *pTxData, DWORD nTxSize )
int Initialize ( BYTE pm, BYTE *pTxData, DWORD nTxSize, BYTE *pRxData, DWORD *nRxSize )
到目前为止,我已经做到了这一点。我用以下代码创建了一个静态类。
C ++中的*
是什么意思?我们是否需要在.NET中包含任何额外的关键字?
有时在参数名称[BYTE *pTxData
]之前,有时在数据类型[char*
]
[DllImport("MACHINE.dll")]
public static extern int SetTimeouts(uint dwTxTimeout, uint dwRxTimeout);
[DllImport("MACHINE.dll")]
public static extern int ListDevices(uint hWnd, char text, uint caption);
[DllImport("MACHINE.dll")]
public static extern int SetDescription(char pDescription);
[DllImport("MACHINE.dll")]
public static extern int OpenDevice(int iDeviceType, char pData, int iDataType);
[DllImport("MACHINE.dll")]
public static extern int GetVersion(int iCode, ushort pCode, byte pData);
[DllImport("MACHINE.dll")]
public static extern int Read(byte pm, byte pRxData, uint nRxSize);
[DllImport("MACHINE.dll")]
public static extern int Write(byte pm, byte pTxData, uint nTxSize);