pajm pajm - 1 month ago 19
Python Question

Python import dll

How would I import a winDLL into python and be able to use all of its functions? It only needs doubles and strings.

Answer

You've tagged the question ctypes and so it sounds like you already know the answer.

The ctypes tutorial is excellent. Once you've read and understood that you'll be able to do it easily.

For example:

>>> from ctypes import *
>>> windll.kernel32.GetModuleHandleW(0)
486539264

And an example from my own code:

lib = ctypes.WinDLL('mylibrary.dll')
#lib = ctypes.WinDLL('full/path/to/mylibrary.dll')
func = lib['myFunc']#my func is double myFunc(double);
func.restype = ctypes.c_double
value = func(ctypes.c_double(42.0))