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

Chetan pandyacus.xspam at xspam.sbcglobal.net
Tue Oct 24 21:21:14 EDT 2006


"Mudcat" <mnations at gmail.com> 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



More information about the Python-list mailing list