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

M

Mudcat

Hi,

I can't figure out why ctypes won't load the DLL I need to use. I've
tried everything I can find (and the ctypes website is down at the
moment). Here's what I've seen so far.

I've added the file arapi51.dll to the system32 directory. However
when I tried to access it I see this:
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
File "C:\Python24\Lib\site-packages\ctypes\__init__.py", line 387, in
__getattr__
dll = 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

So then I use the find_library function, and it finds it:
'C:\\WINNT\\system32\\arapi51.dll'

At that point I try to use the LoadLibrary function, but it still can't
find it:
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? I've used ctypes before and not had this
problem. Before, I've just added the file to the system32 directory and
not had this problem.

On another note, if I wanted to include these DLL's to be a part of an
installable package, how would I configure ctypes to use DLL's from a
local directory?

Thanks,
Marc
 
B

Bruno Desthuilliers

Mudcat a écrit :
Hi,

I can't figure out why ctypes won't load the DLL I need to use. I've
tried everything I can find (and the ctypes website is down at the
moment). Here's what I've seen so far.

I've added the file arapi51.dll to the system32 directory. However
when I tried to access it I see this:
(snip)
WindowsError: [Errno 126] The specified module could not be found

So then I use the find_library function, and it finds it: (snip)
At that point I try to use the LoadLibrary function, but it still can't
find it: (snip)
WindowsError: [Errno 126] The specified module could not be found

What am I doing wrong? I've used ctypes before and not had this
problem. Before, I've just added the file to the system32 directory and
not had this problem.

Looks like it could have to do with another dll arapi51.dll depends upon
that would be missing, cf:
http://aspn.activestate.com/ASPN/Mail/Message/ctypes-users/2593616

HTH
 
C

Chetan

Is the DLL loadable from a standalone C program?
All that is needed is a call to LoadLibrary() and check the return.

If the full path is not specified, the dll is searched in the predefined order
- I believe it is
executable directory - in this case, directory of python.exe
current directory - set the current drive and path to whereever you want
before trying to load the dll
windows system directory
windows directory
Directories specified in PATH evnvironment variable

-Chetan
Hi,

I can't figure out why ctypes won't load the DLL I need to use. I've
tried everything I can find (and the ctypes website is down at the
moment). Here's what I've seen so far.

I've added the file arapi51.dll to the system32 directory. However
when I tried to access it I see this:
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
File "C:\Python24\Lib\site-packages\ctypes\__init__.py", line 387, in
__getattr__
dll = 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

So then I use the find_library function, and it finds it:
'C:\\WINNT\\system32\\arapi51.dll'

At that point I try to use the LoadLibrary function, but it still can't
find it:
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? I've used ctypes before and not had this
problem. Before, I've just added the file to the system32 directory and
not had this problem.

On another note, if I wanted to include these DLL's to be a part of an
installable package, how would I configure ctypes to use DLL's from a
local directory?

Thanks,
Marc
 
J

Jon Clements

Mudcat wrote:

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

'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:
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'

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

Jon.
 
C

Chetan

Jon Clements said:
Mudcat wrote:

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

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

Uh oh, escaped:'C:\\winnt\\system32\x07rapi51.dll'
I wondered about it, but that would not explain why it fails in the first case
- perhaps the OP now knows what happened. Interestingly I get a different
error with the distribution binary for 2.5 - I get "Error 22" instead of "Errno
126", but the message text was same, so I assumed this was from a different
version and something had changed about how the errno is reported.

However, I checked the windows error codes and 126 seems to be the correct
error. The error code talks about bad command and the corresponding message
text reads "The device does not recognize the command."

-Chetan
 
M

Mudcat

That was it. Once I added the other DLLs then it was able to find and
make the call.

Thanks for all the help,
Marc


Bruno said:
Mudcat a écrit :
Hi,

I can't figure out why ctypes won't load the DLL I need to use. I've
tried everything I can find (and the ctypes website is down at the
moment). Here's what I've seen so far.

I've added the file arapi51.dll to the system32 directory. However
when I tried to access it I see this:
(snip)
WindowsError: [Errno 126] The specified module could not be found

So then I use the find_library function, and it finds it: (snip)
At that point I try to use the LoadLibrary function, but it still can't
find it: (snip)
WindowsError: [Errno 126] The specified module could not be found

What am I doing wrong? I've used ctypes before and not had this
problem. Before, I've just added the file to the system32 directory and
not had this problem.

Looks like it could have to do with another dll arapi51.dll depends upon
that would be missing, cf:
http://aspn.activestate.com/ASPN/Mail/Message/ctypes-users/2593616

HTH
 
B

Bruno Desthuilliers

Mudcat a écrit :
That was it. Once I added the other DLLs then it was able to find and
make the call.

Thanks for all the help,

I just googled for "WindowsError: [Errno 126]" and followed the links,
you know...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top