找不到从 VB6 调用C++ DLL 程序
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:MathFlyCapture2binPGLCTrigger.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:MathFlyCapture2binPGLCTrigger.dll" () As Long
定义文件:
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 无法加载,并且您确定它在那里,则它可能缺少依赖项。使用依赖关系步行者调试它。加载可执行文件并从"配置文件"菜单以配置文件模式运行它。这将记录加载程序事件,你将看到失败的确切原因。
你需要告诉 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 是任意但不同的正整数,称为序数。几点评论:
VB 中的Long
是C++中的int
。
可以使用 __declspec(dllexport)
和 extern "C" {/*your function here*/}
代替 .def 文件。
相关文章:
- 为什么导入Mixed native/CLR lib.dll的本机C++应用程序没有在Mixed lib.dll中的外部变
- 如何在 64 位 vb.net Windows 应用程序中引用 32 位 dll
- 程序无法启动,因为缺少 libmpc-3.dll
- C# DLL 从C++应用程序调用 SOAP Web 服务
- 将 c++ 生成器应用程序与外部 dll 结合使用
- DLL Made with CMake 使程序崩溃
- WinDeployqt 不会为调试应用程序部署 Qwindowsd.dll
- Log4net,将日志消息从 c++ dll 发送到 c# 应用程序?
- 调试 ASP MVC 应用程序中使用的C++ DLL
- 系统错误:程序无法启动,因为您的计算机中缺少MSVCP140D.DLL。尝试重新安装该程序以解决此问题
- 如何使特定程序仅从安装的路径运行以避免DLL劫持
- Qt应用程序找不到第三方DLL并崩溃
- 如何将从控制台应用程序C++回调设置为C++ COM DLL
- 64 位进程中的 AnyCPU C# DLL 无法引用 64 位C++ DLL(给出错误:无法加载文件或程序集)
- 我可以用C++/WinRT编写一个DLL,供windows桌面应用程序(而不是UWP)或Unity插件使用吗
- 名为DLL的C++windows服务程序工作不正常
- 是否可以在C++中基于程序集输出(.dll或.exe)定义变量
- .NET核心应用程序无法加载C++DLL
- 找不到从 VB6 调用C++ DLL 程序
- 在不引用DLL/程序集的情况下加载WinRT组件