vb调用VC的DLL中结构体参数传递问题,搜遍百度,GOOGLE也没有找到答案,请高手赐教!
VB调用VC的DLL中,有一参数为RECT,RECT在VC里为结构体,其定义为:
typedef struct tagRECT {
LONG left;
LONG top;
LONG right;
LONG bottom;
} RECT;
在VB调用时,需要定义与RECT相对应的类型,定义为:
Public Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
在VB里的调用声明:
Public Declare Function codeBar Lib "CodeBar.dll" Alias "_codeBar@36" (ByVal pBitInfoHead As Long, ret As RECT, ByVal gray As Long, ByVal EXT As Long, ByVal way As Long, ByVal barType As Long) As Long
在VB里调用VC的DLL:
dim ret as RECT
dim ImagePtr as LONG '此变量为指针,用二进制表示地址
dim lTag as LONG '此变量为指针,用二进制表示地址,返回值也是个指针
lTag = codeBar(ImagePtr, ret, 150, m_39, 15, 1)
调用时出现约定错误,错误代码为49
--------------------编程问答-------------------- 你函数原型先看看,是不是__stdcall的 --------------------编程问答-------------------- 函数原型是__stdcall,这个没有问题的,只是参数的问题才出现约定错误. --------------------编程问答-------------------- 把VB声明的结构类型的名字改成与dll中一样的名字试一下 --------------------编程问答-------------------- 那么就是你函数声明的问题了
你把函数原型贴来看看 --------------------编程问答-------------------- 首先把C++的原型贴出来。 --------------------编程问答--------------------
VC里的函数原型:
CODEBARDLL_API DecodeInfo* _stdcall codeBar(LPBYTE pDib,RECT rect,BYTE gray,bool EXT,int way,int barType); --------------------编程问答-------------------- 听某位老兄说,在VB调用VC里的DLL,不能用VB的自定义类型作为参数, --------------------编程问答-------------------- Public Declare Function codeBar Lib "CodeBar.dll" Alias "_codeBar@36" (ByVal pBitInfoHead As Long, ret As RECT, ByVal gray As Byte, ByVal EXT As Byte, ByVal way As Long, ByVal barType As Long) As Long --------------------编程问答-------------------- 函数的第1个参数要给一个地址,ImagePtr赋值了吗?
补充:VB , 基础类