下面是VB调用C的WIN32动态连接库的程序,Source2字串传递正确,Source1作为数组怎么也传递不正确,请各位大虾指点。VB程序:Private Declare Function test Lib "F:\XUXI\C++6练习\test\Debug\test.dll" (ByRef Source1() As Long, ByVal Source2 As String) As Boolean
Private Sub Command1_Click()
     Dim Source1(1 To 6) As Long, Source2 As String     Source1(1) = 1: Source1(2) = 2: Source1(3) = 3: Source1(4) = 4: Source1(5) = 5: Source1(6) = 6:
     Source2 = "Basic"
     ret = test(Source1, Source2)
     If ret = True Then
        End
     Else
        rt = MsgBox("Dll函数错误", vbOKOnly)
        End
     End If
End Sub
WIN32动态连接库:
// test.cpp#include "StdAfx.h"
#include <stdio.h>
#include "test.h"
void succode(double Source1[],char *Source2);BOOL APIENTRY DllMain( HANDLE hModule, 
                       DWORD  ul_reason_for_call, 
                       LPVOID lpReserved
 )
{
    return TRUE;
}EXPORT BOOL CALLBACK test(double Source1[],char *Source2)
{
succode(Source1,Source2);
return TRUE;
}void succode(double Source1[],char *Source2)
{
int i;
for(i=0;i<6;i++)
printf("%20.12f",Source1[i]);
}test.def:
;test.def:Declares the module parameters for DLL.
LIBRARY "test"
DESCRIPTION 'test test'
EXPORTS
;Explicit export can go here
test//test.h#define EXPORT extern "C" __declspec(dllexport)EXPORT BOOL CALLBACK test(double Source[],char *Source2);

解决方案 »

  1.   

    参数直接传指针,在增加一个数字个数的参数试试。
    VB里的Long对应VC里的double类型?
      

  2.   

    你在vb里定义的source1是long,在dll函数入口类型是double怎么可能对啊?
      

  3.   

    我也用如下的语句定义过,结果还是一样
    Private Declare Function test Lib "F:\XUXI\C++6练习\test\Debug\test.dll" (ByRef Source1() As double, ByVal Source2 As String) As Boolean 再增加一个数字个数的参数试试,什么意思?单个数字变量我想应该能传输吧,我试试看!
      

  4.   

    EXPORT BOOL CALLBACK test(double *Source1, int nSource1Size,char *Source2) 
      

  5.   

    我用如下的语句定义过
    VB:
    Private Declare Function test Lib "F:\XUXI\C++6练习\test\Debug\test.dll" (ByRef Source1() As double, ByVal Source2 As String) As Boolean c:
    EXPORT BOOL CALLBACK test(double *Source1,char *Source2)Watch1里观察Source1[0]、Source1[1]等还是不正确。对于任何变量只要VB里用ByVal传值方式其参数就能正确传递,
    只用ByRef地址方式参数就不能正确传递,但对于数组只能用ByRef,我在C里试了多种方法都没传递成功哦。希望有人能指点一下。