Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Ctypes Error: Why can't it find the DLL.

Reply
Thread Tools

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

 
 
Mudcat
Guest
Posts: n/a
 
      10-24-2006
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:

>>> print windll.arapi51 # doctest: +WINDOWS

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:

>>> find_library('arapi51.dll')

'C:\\WINNT\\system32\\arapi51.dll'

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

 
Reply With Quote
 
 
 
 
Bruno Desthuilliers
Guest
Posts: n/a
 
      10-24-2006
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/Mai...-users/2593616

HTH
 
Reply With Quote
 
 
 
 
Chetan
Guest
Posts: n/a
 
      10-25-2006
"Mudcat" <(E-Mail Removed)> writes:

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:
>
>>>> print windll.arapi51 # doctest: +WINDOWS

> 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:
>
>>>> find_library('arapi51.dll')

> 'C:\\WINNT\\system32\\arapi51.dll'
>
> 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? 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

 
Reply With Quote
 
Jon Clements
Guest
Posts: n/a
 
      10-25-2006

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.

 
Reply With Quote
 
Chetan
Guest
Posts: n/a
 
      10-25-2006
"Jon Clements" <(E-Mail Removed)> writes:

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

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

>
> Jon.

 
Reply With Quote
 
Mudcat
Guest
Posts: n/a
 
      10-28-2006
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 Desthuilliers wrote:
> 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/Mai...-users/2593616
>
> HTH


 
Reply With Quote
 
Bruno Desthuilliers
Guest
Posts: n/a
 
      10-31-2006
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...
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Ctypes can't find libc on Solaris Skip Montanaro Python 0 01-27-2013 12:25 AM
WindowsXP/ CTypes - How to convert ctypes array to a string? dudeja.rajat@gmail.com Python 0 08-19-2008 10:20 AM
why why why why why Mr. SweatyFinger ASP .Net 4 12-21-2006 01:15 PM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
RE: [ctypes-users] [Ann] ctypes 0.9.0 released Henk Punt Python 0 07-23-2004 10:34 PM



Advertisments