Re: Ctypes Error: Why can't it find the DLL.




Mudcat wrote:


So then I use the find_library function, and it finds it:

find_library('arapi51.dll')
'C:\\WINNT\\system32\\arapi51.dll'


Notice it's escaped the '\' character.

At that point I try to use the LoadLibrary function, but it still can't
find it:

windll.LoadLibrary('C:\WINNT\system32\arapi51.dll')
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
File "C:\Python24\Lib\site-packages\ctypes\__init__.py", line 395, in
LoadLibrary
return self._dlltype(name)
File "C:\Python24\Lib\site-packages\ctypes\__init__.py", line 312, in
__init__
self._handle = _dlopen(self._name, mode)
WindowsError: [Errno 126] The specified module could not be found

What am I doing wrong? [snip]

You need to use either
windll.LoadLibrary(r'c:\winnt\system32\arapi51.dll') or escape the \'s
as the find_library function did. You're getting caught out by \a which
is the alert/bell character. \w and \s aren't valid escape sequences so
you get away with them. I'm guessing it's worked before because you've
been lucky.

Works fine!:
'C:\winnt\system32\smtpctrs.dll'
'C:\\winnt\\system32\\smtpctrs.dll'

Uh oh, escaped:
'C:\winnt\system32\arapi51.dll'
'C:\\winnt\\system32\x07rapi51.dll'

Jon.

.



Relevant Pages

  • Re: escaped identifier vs regular names ?
    ... Escaped identifiers are not in a separate namespace from normal ... the terminating whitespace character to be a space character, ... And, yes, many Verilog tools create escaped names of this form. ... escape names, it isn't really handling the entire Verilog language. ...
    (comp.lang.verilog)
  • Re: Unrecognized escape sequences in string literals
    ... character without knowing the context, ... '\n' maps to the string chr. ... In both cases the backslash in the literal have the same meaning: ... escape every backslash, ...
    (comp.lang.python)
  • Re: Unrecognized escape sequences in string literals
    ... a reader can't know if \ is a literal character or escape character ... without knowing the context, and it means an innocuous change in context ... thinking about the fact that the s comes after the backslash. ...
    (comp.lang.python)
  • Re: problems with opening files due to files path
    ... GUI or it is a console app. ... of what an escape character and escape sequence is. ... character) inside a string specially, it makes the character after the ...
    (comp.lang.python)
  • Re: Ctypes Error: Why cant it find the DLL.
    ... Notice it's escaped the '\' character. ... WindowsError: The specified module could not be found ... \w and \s aren't valid escape sequences so ... version and something had changed about how the errno is reported. ...
    (comp.lang.python)