【发布时间】:2011-01-21 00:50:06
【问题描述】:
我正在尝试访问位于 64 位处理器 PC 中“c:/Program Files (x86)”文件夹中的 dll。
如果我使用 os.path.exists 检查 dll 是否存在,我会收到肯定的回答:
>>> print os.path.exists('c:/Program Files (x86)/Some Folder/SomeDll.dll')
True
但是当我尝试使用 ctypes 加载 dll 时,出现以下错误:
>>> from ctypes import WinDLL
>>> some_dll = WinDLL('c:/Program Files (x86)/Some Folder/SomeDLL.dll')
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "C:\Python26\lib\ctypes\__init__.py", line 353, in __init__
self._handle = _dlopen(self._name, mode)
WindowsError: [Error 126] The specified module could not be found
在 32 位 PC 中,dll 位于“c:/Program Files”文件夹中,我可以毫无问题地打开它。我认为问题可能是文件夹名称中存在括号。由于返回的异常是WindowsError,看来是负责加载库的操作系统函数存在缺陷。
所以,问题是:如何加载位于“c:/Program Files (x86)”文件夹中的 dll?我无法将 dll 复制到另一个目的地,它必须位于原始路径中...
谢谢!
【问题讨论】: