VB调用C DLL时的参数传递问题

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 jennyvenus 的 blog

首先必须了解此函数在c中的原型,包括参数类型和传递方式。

c dll 原型         vb声明                 vb调用
 
int a              byval a as long        call func(…,a,…)
long a             byref a as long        call func(…,byval a,…)
int *pa            byref pa as long       call func(…,pa,…)
long *pa           byval pa as long       call func(…,varptr(pa),…)   *(1)
char *pstr         byval pstr as string   call func(…,pstr,…)         *(2)
wchar *pstr        byref pstr as string   call func(…,byval pstr,…)
struct tagx *p     byref p as tagx        call func(…,ptag,…)         *(3) 
handle h           byval h as long        call func(…,h,…)            *(4) 

注意   

1)不推荐使用此方式

2)如果dll要求一个字符串缓冲区,一定要在调用前初始化字串,即dim t as string * 50

3)用户定义子类型必须用byref方式传递, 

4)任何内核对象的句柄(process, thread, module, file, filemapping, semaphore等)和大多数gdi对象的句柄都能用此方式传递。 

本文关键:none
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top