在用vb调用vc生成的dll时,如果调用的函数参数类型为自定义构造体类型时,编译时显示dll调用错误。代码如下:
vc部分:
typedef struct{
int i;
int j;
} Item;__declspec(dllexport) int __stdcall add(Item item)
{
int c = 0;
c = item.i + item.j;
return c;
}EXPORTS add @1vb部分:
Public Type ITEM
i As Integer
j As Integer
End TypePrivate Declare Function add Lib "xxx.dll" (ByRef t As ITEM) As IntegerPrivate Sub Command1_Click()
Dim rt As Integer
Dim it As ITEM
it.i = 1
it.j = 2
rt = add(it)
End Sub请问是什么原因?
vc部分:
typedef struct{
int i;
int j;
} Item;__declspec(dllexport) int __stdcall add(Item item)
{
int c = 0;
c = item.i + item.j;
return c;
}EXPORTS add @1vb部分:
Public Type ITEM
i As Integer
j As Integer
End TypePrivate Declare Function add Lib "xxx.dll" (ByRef t As ITEM) As IntegerPrivate Sub Command1_Click()
Dim rt As Integer
Dim it As ITEM
it.i = 1
it.j = 2
rt = add(it)
End Sub请问是什么原因?
__declspec(dllexport) int __stdcall add(Item item)
改成
__declspec(dllexport) int __stdcall add(Item *item)
编译ok了
不过你的建议帮我解决了另外一个问题
3q!