下面是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);
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);
解决方案 »
- 关于图标颜色的问题
- 断言错误 在ASSERT(m_hObject == NULL)
- OLE DB 打开会话 Prepare()错误 会是什么原因?
- 关于对话框的错误(在线等。。。)
- 加入datagrid ctrl 控件后编译显示:Cannot open include file: 'datagrid.h': No such file or directory,WHY?
- 对话框中怎么捕获与判别CEdit的ENCHANGE消息....
- 简单问题,在线等!!急,谢谢!!
- 已知窗口的句柄,有什么方法让这个窗口处在当前状态(激活)
- 绝对的VC、COM新手,求ATL DLL字符串传输的例子,还请高手指教
- 在CTreeCtrl中同时使用系统图标与自定义图标的问题??
- 线程高手来看看。(简单)
- 这是因为什么原因 引起的 啊 ????
VB里的Long对应VC里的double类型?
Private Declare Function test Lib "F:\XUXI\C++6练习\test\Debug\test.dll" (ByRef Source1() As double, ByVal Source2 As String) As Boolean 再增加一个数字个数的参数试试,什么意思?单个数字变量我想应该能传输吧,我试试看!
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里试了多种方法都没传递成功哦。希望有人能指点一下。