user15824070
user15824070

Reputation:

Calling function from dll in Python

I'm trying to call a few functions in a .dll file from my python program but my python program can't find the functions at all. I've used a few different ctypes methods but haven't gotten anywhere.

I've tried:

self.dll = ctypes.WinDLL('C:\Windows\System32\DLLNAME')

self.dll = cdll.LoadLibrary('C:\Windows\System32\DLLNAME')

self.dll = CDLL('C:\Windows\System32\DLLNAME')

where DLLNAME is the name of my dll. I have double and triple checked that the dll is in the win\sys32 library and has the same name.

I'm then going down to the next line and saying

self.dll.USB_PM()

where USB_PM() is the name of the first function I need to access. This throws the error

AttributeError: function 'USB_PM' not found

This is taking place in a class, hence the self. included there.


PC: Windows 10

Python: 3.9, 32 bit

DLL: MiniCircuits activex DLL, registered with RegSvr32

DLL can be found here

Upvotes: 0

Views: 1118

Answers (1)

Mark Tolonen
Mark Tolonen

Reputation: 178314

32-but apps cannot read or write c:\windows\system32 on 64-bit to prevent using or corrupting the 64-bit DLLs there. 32-bit apps are redirected to c:\windows\syswow64 instead. Place your 32-bit DLL there and simply use:

dll = WinDLL('dllname')

Path isn’t required as that directory is a standard search path for DLLs.

Upvotes: 0

Related Questions