Can I wrap a Windows DLL to use it in Python under Linux?
Is it possible to wrap a Windows DLL (a driver for specific hardware) to use it from Python under Linux.
If yes, what’s the best way to do it?
Disclaimer: Depending on the context, the following is certainly not the best approach. This is just a possible approach that fits the description.
I wrote a small Python module to call Windows DLLs from Python on Linux. It is based on IPC between regular Linux/Unix Python processes and Wine-based Python processes. Because I myself need it in too many different use cases/scenarios, I designed it as “generic”
ctypes module direct replacement, Automate most of the required pipelines in the background.
Example: Let’s say you use Python on Linux, have Wine installed, and want to call
msvcrt .dll (Microsoft C runtime library). You can do the following:
from zugbruecke import ctypes dll_pow = ctypes.cdll.msvcrt.pow dll_pow.argtypes = (ctypes.c_double, ctypes.c_double) dll_pow.restype = ctypes.c_double print('You should expect "1024.0" to show up here: "%.1f".' % dll_pow(2.0, 10.0))
It’s still a bit rough on the edges (i.e. alpha and unsafe), but it does handle most types of parameters (including pointers).
I’m really interested to see how it behaves and performs when used with hardware drivers. Feedback is very welcome!