易截截图软件、单文件、免安装、纯绿色、仅160KB

请教:VB调用VC dll 报错 - .NET技术 / VB.NET

VC中的导出的函数是这样的:

extern "C" __declspec(dllexport)
HRESULT Connect(LPCSTR IpAddr, CHAR* pcUserName = NULL, CHAR* pcPassword = NULL)//返回0表示连接成功,非0则失败
{
  ...
}

我在VB中声明如下:

Declare Function Connect Lib "C:\example.dll" (ByVal IpAddr As String, ByVal UserName As String, ByVal Passwd As String) As Integer

同时,我定义

Const NULL = 0

然后调用:

Dim result As Integer

result = Connect("138.139.0.230", NULL, NULL)

If result <> 0 Then

  MsgBox("error_connect")

  Return

End If

结果总是报错,请问哪里不对呢?


Const NULL = Nothing

报错信息是什么?

看下:
result = Connect("138.139.0.230", nothing, nothing)


result = Connect("138.139.0.230", String.Empty, String.Empty)?

用nothing试过了,还是不行,报错就是说 result 不等于0

进入到 MsgBox("error_connect")


String.Empty也试过了,返回值也非0。

把后两个参数的ByVal改成ByRef也不行。。。

result = Connect("138.139.0.230", NULL, NULL)
-----------
你看一下,它返回的不是0,返回的具体是个什么东西?调试一下或者直接吧结果MsgBox出来

返回的就是一个负值:-1071579135

我用VC写的程序调用这个Connect函数:

HRESULT result


相关问答:

vb - VB / 基础类

数据库里有一个字段的内容是二进制,怎么才能把这个二进制读出来
使用字节流对象可以实现

例如现在数据库里有个字段的内容是0x504B03040A0000000800407F263C3B02465390000000820000000A0000006273CECACCE22E7478 ......

vb - VB / 非技术类

怎么把已知的数据保存成xml文件,现在已知的数据是
<?mso-application progid="Excel.Sheet"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
 xmlns:o=& ......

vb生成EXE - VB / 基础类

form1中有text1-8, 和command1 
text8中为程序代码(生成窗体为form2(已做好))
单击command1后将text2中的代码生成EXE到d:\ 并且text1-7分别对应
产品名 公司名 合法版权 合法商标 文件描述 注释 标题 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号