下面是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);