VB6 API 声明路径

发布于 2024-08-05 12:31:48 字数 1070 浏览 7 评论 0原文

我在模块中有以下声明:

Private Declare Function gzopen Lib "ZLIB.DLL" (ByVal filePath As String, ByVal mode As String) As Long

函数中的以下代码行失败,并出现“找不到文件:ZLIB.DLL”错误:

lGZFileHandle = gzopen(sPath, "rb")

我知道 ZLIB 不需要注册。我的问题是,ZLIB.DLL 需要存放在哪里才能使我的代码正常工作?我还知道这段代码正在另一台机器上运行。目前,我的 ZLIB.DLL 与应用程序 exe 位于同一文件夹中。

更新

令我松了口气的是,代码在编译后确实可以工作。但在 IDE 中运行时不起作用(它在另一台机器上起作用)。我的应用程序文件夹中仍然有 ZLIB.DLL。 这意味着必须检查应用程序路径才能加载 DLL。

为了解决这个问题,我尝试过:

Private Declare Function SetDllDirectory Lib "Kernel32" Alias "SetDllDirectoryA" (ByVal path As String) As Long

然后在函数中:

SetDllDirectory App.path

这似乎允许加载 DLL,但随后我收到“错误的 DLL 调用约定”错误。情节变得更加复杂。

已解决

答案似乎在这里:http://www.zlib.net /DLL_FAQ.txt。我想这是 RTFM 的一个例子。 因此,奇怪的是,在 IDE 中,STD_CALL 约定有效,但一旦编译,C 样式调用约定就足够了。它仍然没有解释为什么它在 IDE 中可以在不同的机器上工作。呵呵。

感谢大家为我指明了正确的方向。

I have the following declaration in a Module:

Private Declare Function gzopen Lib "ZLIB.DLL" (ByVal filePath As String, ByVal mode As String) As Long

The following code line in a function fails, with a 'File Not Found: ZLIB.DLL' error:

lGZFileHandle = gzopen(sPath, "rb")

I'm aware that ZLIB doesn't need to be registered. My question is, where does ZLIB.DLL need to live in order for my code to work? I also know that this code is working on another machine. Currently I have ZLIB.DLL in the same folder as the application exe.

UPDATE

To my relief, the code does work when compiled. But does not work whilst running in the IDE (it does on a different machine). I still have ZLIB.DLL in the application folder.
This means that the application path must be being checked for loading the DLL.

To get around this I have tried:

Private Declare Function SetDllDirectory Lib "Kernel32" Alias "SetDllDirectoryA" (ByVal path As String) As Long

and then in the function:

SetDllDirectory App.path

This seems to allow the DLL to load, but I then get a 'Bad DLL calling convention' error instead. The plot thickens.

SOLVED

The answer seems to be here: http://www.zlib.net/DLL_FAQ.txt. It's a case of RTFM I suppose.
So, bizzarely whilst in the IDE, the STD_CALL convention is in force, but once compiled the C style calling convention suffices. It still doesn't explain why it works on a different machine in the IDE. Ho hum.

Thanks all for pointing me in the right direction.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

零度° 2024-08-12 12:31:48

VB6 偏离了 Ken 建议的搜索协议(此 链接是快速参考)。

通常的问题是 .exe 路径(列表中的搜索位置#1)不是 VB 程序的路径,而是 VB6 IDE 的路径。因此,将 DLL 放在 VB 程序的位置是没有好处的——除非您将 VB6 快捷方式的“开始位置”更改为指向该位置。

或者,您可以将 DLL 放在我的链接中指定的其他位置之一。

VB6 strayed a bit from the search protocol suggested by Ken (this link is the quick reference).

The usual problem is that the .exe path (search location #1 on the list) is not the path of your VB program, but rather the VB6 IDE. So putting the DLL in the location of your VB program is no good -- unless you change the 'Start In' location of your VB6 shortcut to point to that location.

Alternately, you can put the DLL in one of the other locations specified in my link.

淡看悲欢离合 2024-08-12 12:31:48

通过 Visual Studio IDE 运行时,所有相关文件需要放置在以下文件夹中:
C:\Program Files\Microsoft Visual Studio\VB98\

这是因为调试时运行的 exe 驻留在该文件夹中。这将允许您在不更改任何路径的情况下进行调试。

When running through the Visual Studio IDE, all relative files need to be placed in the following folder:
C:\Program Files\Microsoft Visual Studio\VB98\

This is because the exe that is running while debugging resides in that folder. This will allow you to debug without changing any paths.

殊姿 2024-08-12 12:31:48

ZLib 必须位于标准 DLL 加载搜索路径中。有关详细信息,请参阅 MSDN LoadLibrary 文档DLL 的查找方式以及搜索顺序。

ZLib has to be in the standard DLL load search path. See the MSDN LoadLibrary documentation for specifics on the way DLLs are found and the order of the search for them.

野鹿林 2024-08-12 12:31:48

您确定 ZLIB 不需要注册吗?

我建议您注册并重试。

编辑
尝试将 DLL 放入系统文件夹中。我相信你的程序会在那里检查它。

Are you sure ZLIB doesn't have to be registered?

I suggest you register it and try again.

EDIT
Try putting the DLL in your System folder. I believe your program will check there for it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文