使用ctypes(python)在带括号的路径中加载dll时出错

Fel*_*rri 5 python dll ctypes

我正在尝试访问位于64位处理器PC中"c:/ Program Files(x86)"文件夹中的dll.

如果我使用os.path.exists来检查dll是否存在,我会得到一个肯定的答案:

>>> print os.path.exists('c:/Program Files (x86)/Some Folder/SomeDll.dll')
True
Run Code Online (Sandbox Code Playgroud)

但是当我尝试使用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
Run Code Online (Sandbox Code Playgroud)

在32位PC中,dll位于"c:/ Program Files"文件夹中,我可以毫无问题地打开它.我想也许问题是文件夹名称中是否存在括号.由于返回的异常是WindowsError,它似乎是负责加载库的操作系统函数中的一个缺陷.

所以,问题是:如何加载位于"c:/ Program Files(x86)"文件夹中的dll?我无法将dll复制到另一个目的地,它必须位于原始路径中...

谢谢!

luc*_*luc 7

你试过"C:/ Progra~1/SomeFolder/SomeDll"吗?

另一个建议是:

 os.chdir(r"C:\Program Files(x86)\SomeFolder")
 the_dll = WinDLL("SomeDLL.dll")      
Run Code Online (Sandbox Code Playgroud)