帮忙看看C#调用DLL问题?
DLL:Mr3001ADll.dll函数:ConnectReader 打开串口
已知:hCom=0,nTransmode=1
VB中声明如下:
Public Declare Function ConnectReader Lib "Mr3001ADll.dll" (ByRef hCom As Long, ByVal nTransmode As Long, ByVal nNetPort As Long, ByVal strReaderIP As String, ByVal strSerialNum As String, ByVal nBaudRate As Integer) As Integer
VB中调用
Result = ConnectReader(hCom, Workmode, nNetPort, strReaderIP, StrComm, 9600) 使用正常,能打开串口。
我把他在C#中引用:
[DllImport("Mr3001ADll.dll",
EntryPoint = "ConnectReader",
CharSet = CharSet.Unicode )]
public static extern int ConnectReader(
ref long hCom,
long nTransmode,
long nNetPort,
string strReaderIP,
string strSerialNum,
int nBaudRate);
调用:
if (0 == RfidApiLib.ConnectReader(ref hCom, nTransmode, nNetPort, strReaderIP, "com1",9600))
{
MessageBox.Show("ok");
}
else
{
MessageBox.Show("no");
}
没有打开串口?请问是什么原因?
--------------------编程问答-------------------- vb里的StrCom字符串是等于"com1"吗? --------------------编程问答-------------------- "com1"换成"COM1" 试试 --------------------编程问答-------------------- 不行,VB里 StrCom是等于COM1 --------------------编程问答-------------------- 高手们帮帮忙啦!
补充:.NET技术 , C#