那时指针吗?是不是要个数组啊!不知道行不行 Declare Function write_card Lib "HLApi.dll" (ByVal card As Integer, ByVal cardtype() As String, ByVal buffer() As String) As Integer
C DLL 原型 VB声明
int a ByVal a as long long a ByRef a as long int *pa ByRef pa as long long *pa ByVal pa as long char *pstr ByVal pstr as string wchar *pstr ByRef pstr as string struct tagX *p ByRef p as tagX HANDLE h ByVal h as long
unsigned char *CardType 对应变体变量
谢谢楼上两位的回复,7楼兄弟的 char *pstr byval pstr as string 肯定是不对的。8楼兄的建议我正在测试,看看有效果否,可能我就是没有试验定义为变体变量了。总有漏网之鱼 (*^__^*) 嘻嘻……!
Declare Function write_card Lib "HLApi.dll" (ByVal card As byte, ByVal cardtype As long, ByVal buffer As long) As longDim cardtype() As byte dim card as byte Dim buffkx() As byte buffkx = StrConv("1A571EFF01020508090313000809041200123456", vbFromUnicode) redim preserve buffkx(ubound(buffkx)+1) '最后的一个0 cardtype = StrConv("23" ,vbFromUnicode) redim preserve cardtype (ubound(cardtype )+1) '最后的一个0 card = 7 Rvalue = write_card(card, varptr(cardtype(0)), varptr(buffkx(0)) 这样试下看看另外,内存错误,是某地址不可读,还是不可写?你这个API仅是把这些值写入到卡里,而不需要从参数里返回值吗?
内存报错, 该内存不能为"read"的报错提示。还有这个参数仅仅是把内容写到卡里并不返回值!
试试这样Declare Function write_card Lib "HLApi.dll" (ByVal card As byte, ByVal cardtype As String, ByVal buffer As String) As Integer Dim cardtype As String * 256 dim card as byte Dim buffkx As String * 256
函数原型(用c++写的):
__HotelLock__ int __stdcall write_card(unsigned char Card,unsigned char *CardType,unsigned char *Buffer);
我在vb里的声明以及调用方法:
Declare Function write_card Lib "HLApi.dll" (ByVal card As Integer, ByVal cardtype As String, ByVal buffer As String) As Integer
调用方法 Dim cardtype As string *2
dim card as integer
Dim buffkx As String * 55
buffkx = "1A571EFF01020508090313000809041200123456"
cardtype = "23"
card = 7
Rvalue = write_card(card, cardtype, buffkx)
执行 write_card的时候报内存错误!请诸位高手指点一下,共同学习。
2楼的,生死有命,富贵在天。要死的时候是谁都拦不住的,或许你应该相信科学,去医院看看把!
Declare Function write_card Lib "HLApi.dll" (ByVal card As Integer, ByVal cardtype() As String, ByVal buffer() As String) As Integer
int a ByVal a as long
long a ByRef a as long
int *pa ByRef pa as long
long *pa ByVal pa as long
char *pstr ByVal pstr as string
wchar *pstr ByRef pstr as string
struct tagX *p ByRef p as tagX
HANDLE h ByVal h as long
对应变体变量
dim card as byte
Dim buffkx() As byte buffkx = StrConv("1A571EFF01020508090313000809041200123456", vbFromUnicode)
redim preserve buffkx(ubound(buffkx)+1) '最后的一个0
cardtype = StrConv("23" ,vbFromUnicode)
redim preserve cardtype (ubound(cardtype )+1) '最后的一个0
card = 7 Rvalue = write_card(card, varptr(cardtype(0)), varptr(buffkx(0))
这样试下看看另外,内存错误,是某地址不可读,还是不可写?你这个API仅是把这些值写入到卡里,而不需要从参数里返回值吗?
dim card as byte
Dim buffkx As String * 256
buffkx = "1A571EFF01020508090313000809041200123456"
cardtype = "23"
card = 7
Rvalue = write_card(card, cardtype, buffkx)
既然是内存不可读,那你这样试一下看看:还是使用我的那种代码,不过在调用API前,先MSGBOX "&H" & hex(varptr(cardtype(0))) & "/&H" & hex(varptr(buffkx(0)))打印出这两个地址后,再看看出错时是什么地址不可读,看看是不是超过了上面某个地址加上其内容长度的位置.我在猜想是DLL里面决定字符串参数结尾的方法与VB的不同,所以才造成不断地向某个指针的后面读;由于一直没有读到结束符号,所以读到了不可读的内存,造成错误.另外最好与DLL作者联系一下,毕竟这个问题由他协助解决的话会容易得多,大家也不用猜来猜去,你也不用试来试去
看看会不会是Byval Byref 的问题.