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

Mudcat mnations at gmail.com
Tue Oct 24 13:40:30 EDT 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




More information about the Python-list mailing list