vb中调用dll中的函数,无法获取返回的字符数组

ddh125 2009-01-22 12:17:43
有一个vc写的dd.dll中的函数
int gen_mcard(
unsigned char *in, //输入
unsigned char out[8],  //输出
unsigned char ivec[8], //输入
unsigned char k[8],//输入
int len//输入
);

如果要在vb中调用,该如何在vb中申明呢??
Private Declare Function gen_mcard_mac Lib "dd.dll" _
(jstr1 As String, ByRef jstr2 As String, ByRef jstr3 As String, _
ByRef jstr4 As String, ByVal jlen As Long) _
As Integer


Dim jstr1 As String
Dim jstr2(16) As String
Dim jstr3(16) As String
Dim jstr4(16) As String
Dim jlen As Long
jstr3(0) = "0"
jstr3(1) = "0"
jstr3(2) = "0"
jstr3(3) = "0"
jstr3(4) = "0"
jstr3(5) = "0"
jstr3(6) = "0"
jstr3(7) = "0"
jstr3(8) = "0"
jstr3(9) = "0"
jstr3(10) = "0"
jstr3(11) = "0"
jstr3(12) = "0"
jstr3(13) = "0"
jstr3(14) = "0"
jstr3(15) = "0"

'E5ECC87CD31A517C

jstr4(0) = "E"
jstr4(1) = "5"
jstr4(2) = "E"
jstr4(3) = "C"
jstr4(4) = "C"
jstr4(5) = "8"
jstr4(6) = "7"
jstr4(7) = "C"
jstr4(8) = "D"
jstr4(9) = "3"
jstr4(10) = "1"
jstr4(11) = "A"
jstr4(12) = "5"
jstr4(13) = "1"
jstr4(14) = "7"
jstr4(15) = "C"

jm = gen_mcard_mac(jstr1, jstr2(0), jstr3(0), jstr4(0), jlen)

jstr2无返回信息!!何解??

...全文
195 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
hanvan 2009-02-04
  • 打赏
  • 举报
回复
up
carefire 2009-01-29
  • 打赏
  • 举报
回复
3. 1楼所说:“VC 中的 char[8] 参数都应该改成 char*” 是对的,这样才是传址方式,才能返回。
carefire 2009-01-29
  • 打赏
  • 举报
回复

1. vb使用stdcall方式处理栈,c默认使用cdecl方式处理栈,这两种方式是完全不同的!!!(原因就在这里)
所以必须这样定义:stdcall int gen_mcard()

2. vb的字符串是bstr类型,而unsigned char对应vb的byte类型,
2楼帮你改正了函数声明,注意不要超出数组界限。
of123 2009-01-22
  • 打赏
  • 举报
回复
int gen_mcard(
unsigned char *in, //输入
unsigned char out[8],  //输出
unsigned char ivec[8], //输入
unsigned char k[8],//输入
int len//输入
);

Private Declare Function gen_mcard Lib "dd.dll" _
(Byref jstr1 As Byte, ByRef jstr2 As Byte, ByRef jstr3 As Byte, _
ByRef jstr4 As Byte, ByVal jlen As Long) As Long

Dim jstr1() As Byte
Dim jstr2(7) As Byte
Dim jstr3(7) As Byte
Dim jstr4(7) As Byte
Dim jlen As Long


'E5ECC87CD31A517C

jstr4(0) = &HE5
jstr4(1) = &HEC
jstr4(2) = &HC8
jstr4(3) = &H7C
jstr4(4) = &HD3
jstr4(5) = &H1A
jstr4(6) = &H51
jstr4(7) = &H7C

Redim jstr1(jlen - 1)
For i = 0 To jlen - 1
'jstr1(i) = ...
Next i

jm = gen_mcard(jstr1(0), jstr2(0), jstr3(0), jstr4(0), jlen)

Tiger_Zhao 2009-01-22
  • 打赏
  • 举报
回复
VC 中的 char[8] 参数都应该改成 char*。
Private Declare Function gen_mcard_mac Lib "dd.dll" _ 
(byval jstr1 As String, ByVal jstr2 As String, ByVal jstr3 As String, _
ByVal jstr4 As String, ByVal jlen As Long) _
As Long

Dim jstr1 As String
Dim jstr2(16) As String
Dim jstr3(16) As String
Dim jstr4(16) As String
Dim jlen As Long

jstr2 = string(8,0)
jstr3 = string(16,0)
jstr4 = "E5ECC87CD31A517C"
jm = gen_mcard_mac(jstr1, jstr2, jstr3, jstr4, jlen)

1,488

社区成员

发帖
与我相关
我的任务
社区描述
VB API
社区管理员
  • API
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧