当前位置:编程学习 > VB >>

vc转VB

VC原码是 
HANDLE icdev; 
unsigned char crlen[2],recbuff[300]; 
int st; 
st=dc_pro_resethex(icdev,crlen,(char *)recbuff); 

我需要的是dc_pro_resethex函数 
请问VB怎么声明这个函数? 
VC是调用一个DDL库,我VB也需要调这个DLL库
 我声明成byref string,程序运行到这个函数时就会崩溃,声明成byref byte,不能正确调用该函数,没有返回任何值
crlen是返回数据的长度,recbuff是返回的数据,ICDEV值是180, --------------------编程问答-------------------- ByRef recbuff() As Byte --------------------编程问答-------------------- byte数组怎么样? --------------------编程问答--------------------
引用 1 楼 liuxu2559 的回复:
ByRef recbuff() As Byte

这样也不行,一调用也崩溃,给数组提前赋值也是崩溃,提示内存不能读 --------------------编程问答-------------------- 首先函数必须是 stdcall 的
declare function dc_pro_resethex lib "..." (byval icdev as long, byref crlen as integer, byref recbuff as byte) as long

dim crlen as integer
dim recbuff(0 to 299) as byte
dim st as long 
st = dc_pro_resethex(180&, crlen, recbuf(0))
--------------------编程问答--------------------
引用 4 楼 Tiger_Zhao 的回复:
首先函数必须是 stdcall 的 

VB codedeclare function dc_pro_resethex lib "..." (byval icdev as long, byref crlen as integer, byref recbuff as byte) as long

dim crlen as integer
dim recbuff(0 to 299) as byte
dim st as long 
st = dc_pro_resethex(180&, crlen, recbuf(0))


Ding.........
--------------------编程问答-------------------- 不过觉得第三个参数似乎有点问题~~~~~
--------------------编程问答-------------------- 顶顶 --------------------编程问答--------------------
引用 4 楼 Tiger_Zhao 的回复:
首先函数必须是 stdcall 的 

VB codedeclare function dc_pro_resethex lib "..." (byval icdev as long, byref crlen as integer, byref recbuff as byte) as long

dim crlen as integer
dim recbuff(0 to 299) as byte
dim st as long 
st = dc_pro_resethex(180&, crlen, recbuf(0))


两个unsigned char 的数组:

unsigned char crlen[2],recbuff[300]; 

一个声明为integer, 一个声明为byte。

字节倒是对上了。不过在VB里给这两个参数赋值有点费脑筋,因为从VC代码的声明看,貌似DLL里是把它们当字符理解的。假设
strCrlen="ok" 'just for an example
strRecBuff="adsf;adkjfa;dk" 


调用的时候如何传过去? --------------------编程问答-------------------- 呵呵。发现楼主最后还有一句话,刚才没看到。那就不问楼上的问题了。 --------------------编程问答-------------------- 用 4F 老鸟的代码没错~~~~~~ --------------------编程问答--------------------
补充:VB ,  基础类
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,