Python calling DLL: TypeError: 'LibraryLoader' object is not callable

Viewed 4329

I am trying to import a DLL into Python 2.7.12 64 bit using ctypes. To narrow down the scope for errors I used Microsoft's MathLibrary DLL example and built my own based on these instructions (https://msdn.microsoft.com/en-GB/library/ms235636.aspx). I built it as x64 release and copied the resulting dll into C:\ root to eliminate path length or spelling error issues. My machine us running Windows 7 Pro 64 Bit.

My python code is:

from ctypes import cdll, windll, c_long, c_int, create_string_buffer

test_dll = windll("C:\\MathLibrary.dll")

add = test_dll.add

When run it reports the following:

Traceback (most recent call last):
  File "C:\temp.py", line 3, in <module>
    test_dll = windll("C:\\MathLibrary.dll")
TypeError: 'LibraryLoader' object is not callable

Can anyone advise what might be the issue?

Thanks

Andy


Update:

@eryksun comment - this removed the LibraryLoader error. However I am now struggling to access the add function and get this error:

    add = test_dll.add
  File "C:\Python27\lib\ctypes\__init__.py", line 375, in __getattr__
    func = self.__getitem__(name)
  File "C:\Python27\lib\ctypes\__init__.py", line 380, in __getitem__
    func = self._FuncPtr((name_or_ordinal, self))
AttributeError: function 'add' not found
3 Answers

Use 'cdll' would produce a similar error message "TypeError: 'LibraryLoader' object is not callable". Use 'CDLL' work well, so the problem is from case sensitive of the 'cdll' and possibly 'windll' as well.

You can try:

test_dll = windll.LoadLibrary("C:\\MathLibrary.dll")
Related