tags:

views:

203

answers:

1

Hello all!

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 "<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

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!

+1  A: 

Have you tried "C:/Progra~1/SomeFolder/SomeDll" ?

Another suggestion:

 os.chdir(r"C:\Program Files(x86)\SomeFolder")
 the_dll = WinDLL("SomeDLL.dll")      
luc
This is weird... If I do "dir /X Pro*.*" in the command prompt to see the short name for all the folders beginning with "Pro", the folder "Program Files" receives the correct short name "PROGRA~1", but the folder "Program Files (x86)" does not receive any short name, so I can not access it using a short name.Any other suggestions?
Felipe Ferri
another suggestion: see my edit
luc
Excellent, it worked! It is a very elegant solution. How didn't I think of that before?? (-:
Felipe Ferri