[英]C++ DLL program called from VB6 cannot be found
我们将C ++程序编译为DLL,并希望在VB6中使用它。 该程序具有诸如
int __stdcall setup(int exposure_time, double shutter, double gain, int numImages) {
....
}
int __stdcall test() {
return 8;
}
Def文件定义为:
LIBRARY
EXPORTS
setup=setup
test=test
我们在VB6中这样声明它们:
Public Declare Function setup Lib "C:\MyDll.dll" () As Long
Public Declare Function test Lib "C:\MyDll.dll" () As Long
然后尝试以以下形式访问:
Private Sub Form_Load()
Debug.Print (test())
End Sub
但是,当执行到达第一个函数调用时,我们在VB中得到“找不到文件”! MyDll.dll程序在声明的位置,并且它不被注册。 缺少什么要声明?
你好拔示巴,
我遵循了您的建议,但是VB程序仍然找不到dll。
VB中的声明:
Public Declare Function setup Lib "C:\Math\FlyCapture2\bin\PGLCTrigger.dll" ( _
ByVal exposure_time As Long, _
ByVal shutter As Double, _
ByVal gain As Double, _
ByVal numImages As Long) As Long
Public Declare Function test Lib "C:\Math\FlyCapture2\bin\PGLCTrigger.dll" () As Long
Def文件:
LIBRARY
EXPORTS
setup=@1
test=@2
C ++程序:
__declspec(dllexport) int __stdcall setup(int exposure_time, double shutter, double gain, int numImages) {
....
}
__declspec(dllexport) int __stdcall test() {
return 8;
}
和VB调用程序:
Private Sub Form_Load()
setup 12, 24#, 1#, 10
test
End Sub
一旦执行击中了上面程序中的设置行,就会出现“找不到dll”错误。
按照在C / C ++中编译DLL的建议,我在.def文件中定义了以下内容,然后从另一个程序调用它 :
//DLL Export-Import definitions
#ifdef BUILD_DLL
#define EXPORT __declspec(dllexport)
#else
#define EXPORT __declspec(dllimport)
#endif
这样我就可以引用DLL中的函数为
EXPORT int __stdcall setup(int exposure_time, double shutter, double gain, int numImages)
但是VS2010会为导入生成一条错误消息。
所以我被困住了。 任何进一步的帮助将不胜感激。 谢谢。
其他人告诉您必须声明该函数的参数。 如果该DLL无法加载,并且您确定它在那里,则很可能缺少依赖项。 使用Dependency Walker调试它。 加载可执行文件,然后从“配置文件”菜单以配置文件模式运行它。 这将记录加载程序事件,您将确切看到失败原因。
您需要告诉VB6 setup
的函数参数:
Public Declare Function setup Lib "C:\MyDll.dll" ( _
ByVal exposure_time As Long, _
ByVal shutter As Double, _
ByVal gain As Double, _
ByVal numImages A Long) As long
我认为您的.def文件不正确。 我用
EXPORTS
setup @1
test @2
其中1和2是任意的但截然不同的正整数,称为ordinals 。 一些注意事项:
VB中的Long
是C ++中的int
。
您可以使用__declspec(dllexport)
和extern "C" {/*your function here*/}
代替.def文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.