I am trying to access a dll located in the "c:/Program Files (x86)" folder in a 64-bits processor PC.
If I use os.path.exists to check if the dll exists, I receive an afirmative answer:
>>> print os.path.exists('c:/Program Files (x86)/Some Folder/SomeDll.dll')
True
But when I try to load the dll using ctypes, I get the following error:
>>> from ctypes import WinDLL
>>> some_dll = WinDLL('c:/Program Files (x86)/Some Folder/SomeDLL.dll')
Traceback (most recent call last):
File "", line 1, in
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
In 32-bit PCs the dll is located in the "c:/Program Files" folder and I can open it without problems. I think that perhaps the problem is the presence of parenthesis in the folder name. As the returned exception was a WindowsError, it seems that it is a flaw in the operating system function responsible of loading libraries.
So, the question is: how do I load a dll located in the "c:/Program Files (x86)" folder? I can't copy the dll to another destination, it must be located in the original path...
Thank you!
解决方案
Have you tried "C:/Progra~1/SomeFolder/SomeDll" ?
Another suggestion:
os.chdir(r"C:\Program Files(x86)\SomeFolder")
the_dll = WinDLL("SomeDLL.dll")