VBA 代码无法访问 System32 中的 DLL [英] VBA code can't access to DLL in System32

查看:39
本文介绍了VBA 代码无法访问 System32 中的 DLL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Windows 7 64 位和 Word 2010 32 位上,我的 VBA 代码无法访问 C:\Windows\System32 文件夹中的 DLL.

My VBA code can't access to my DLL in the C:\Windows\System32 folder on Windows 7 64bit and Word 2010 32bit.

Private Declare Function my_func Lib "mydll.dll" (ByVal param As String) As Long

Public Sub MyFuncTest
  n = my_func("a")
End

我将 mydll.dll 复制到 C:\Windows\System32 并调用了 MyFuncTest,但收到一条错误消息,如错误 53:'mydll.dll' 未找到".

I copied mydll.dll into C:\Windows\System32 and called MyFuncTest but got an error message like "Error 53: 'mydll.dll' not found".

但是,我将代码中的声明更改为:

However, I changed the declaration in code to:

Private Declare Function my_func Lib "C:\Users\myname\Documents\mydll.dll" (ByVal param As String) As Long

然后我将 mydll.dll 复制到 C:\Users\myname\Documents,我帐户的 Documents 文件夹中,并且 MyFuncTest 成功执行.

then I copied mydll.dll into C:\Users\myname\Documents, my account's Documents folder, and MyFuncTest successfully executed.

在声明中将mydll.dll"更改为C:\Windows\System32\mydll.dll"无效.我尝试在同一 VBA 环境中使用 FileSystemObject#FileExists 方法访问 C:\Windows\System32\mydll.dll,但它返回 False(未找到).

Changing "mydll.dll" to "C:\Windows\System32\mydll.dll" in the declaration did not work. And I tried accessing C:\Windows\System32\mydll.dll with FileSystemObject#FileExists method on the same VBA environment, but it returned False (not found).

在 Windows XP 和 Word 2003 上没有问题.

There was no problem on Windows XP and Word 2003.

有人可以帮忙吗?

推荐答案

这是在 64 位 Windows 上的 WOW64 模拟器中运行的 32 位 DLL 和 32 位进程.文件重定向在起作用,因此当 32 位进程查找时system32 实际上是重定向到32位系统目录SysWOW64.

This is a 32 bit DLL and a 32 bit process running in the WOW64 emulator on 64 bit Windows. File redirection is in play and so when a 32 bit process looks in system32 it is actually redirected to the 32 bit system directory SysWOW64.

简单快捷的解决方案是将 DLL 移动到 C:\Windows\SysWOW64.但是,正如 Cody Gray 在评论中指出的那样,不建议您将应用程序 DLL 放在系统目录中.通常的做法是将 DLL 放在程序文件目录下的应用程序文件夹中,并在需要加载 DLL 时确保该文件夹位于 DLL 搜索路径中.

The simple and quick solution is to move the DLL to C:\Windows\SysWOW64. However, as Cody Gray points out in a comment, it is not recommended for you to place application DLLs in the system directory. Normal practice is to place the DLLs in your application folder in the program files directory and make sure that folder is in the DLL search path when the DLL needs to be loaded.

这篇关于VBA 代码无法访问 System32 中的 DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆