【发布时间】:2019-05-08 01:07:33
【问题描述】:
DLL 方法:
[DllImport("SBXPCDLL.dll", CallingConvention = CallingConvention.Winapi)]
static extern byte _ConnectTcpip(Int32 dwMachineNumber, ref IntPtr lpszIPAddress, Int32 dwPortNumber, Int32 dwPassWord);
public static bool ConnectTcpip(Int32 dwMachineNumber, string lpszIPAddress, Int32 dwPortNumber, Int32 dwPassWord)
{
if (lpszIPAddress == null)
return false;
IntPtr string_in = Marshal.StringToBSTR(lpszIPAddress);
try
{
byte ret = _ConnectTcpip(dwMachineNumber, ref string_in, dwPortNumber, dwPassWord);
return ret > 0;
}
catch (Exception)
{
return false;
}
finally
{
Marshal.FreeBSTR(string_in);
}
}
按钮点击事件:
protected void Button_click(object sender, EventArgs e)
{
try
{
bool status = sbxpc.SBXPCDLL.ConnectTcpip(1, ip, 5005, 0);
if (status)
{
bool ss = sbxpc.SBXPCDLL.GetSerialNumber(1, out ip);
Button1.Text = "connected";
Response.Write("success" + ip);
}
}
catch (Exception ee)
{
Response.Write(ee);
}
}
我使用 SBXPCDLL.dll 连接生物识别设备。代码仅适用于第一次,设备已连接,但再次运行时将无法再次连接。我不知道为什么?谁能帮帮我?
【问题讨论】:
-
_ConnectTcpip的返回值是什么? -
@Belurd 刚刚我发现当我停止服务器并再次运行时它会连接。上面的代码第一次工作正常我现在该怎么办?
标签: c# asp.net dll biometrics