如题,用VB2008调用VC++编写的DLL时参数传递老是出错。
用VB调用dll8.dll以实现加法运算并返回和,add函数参数传递时最后一个总是出错,传回的值为前两个数之和,并非3个数之和。在dll8.cpp中代码如下:
_declspec(dllexport) void  _stdcall add(int a,int b,int c)
{
int d; 
d=a+b+c;
char c1[8];
memset(c1,0,8);
itoa(d,c1,10);
MessageBox(NULL,c1,"三个数之和",MB_OK);
}
在dll8.def中代码如下:
LIBRARY "dll8"
EXPORTS
addVB2008中代码:
Public Class Form1
    Private Declare Function add Lib "c:\dll8.dll" (ByVal a As Long, ByVal b As Long, ByVal c As Long) As Long
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        add(3, 4, 5)
    End Sub
End Class由于是新手,故还没有分可以给

解决方案 »

  1.   

    Private Declare Function add Lib "c:\dll8.dll" (ByVal a As Long, ByVal b As Long, ByVal c As Long) As Long
    最后As Long去掉
      

  2.   

    这个问题我自己解决了,原来我用的是VB2008,以前查的资料都是VB6.0的就都不对了
    VB6.0中的Integer对应VB.NET中的SHORT,LONG对应VB.NET中的Integer
    所以VB2008中应改成:
    Public Class Form1
        Private Declare Function add Lib "c:\dll8.dll" (ByVal a As Integer, ByVal b As Integer, ByVal c As Integer) As Integer    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            add(3, 4, 10)
        End Sub
    End Class
    就可以了