[ctypes-users] Seeking reviewers and/or testers - experimental module for calling routines in Windo
Brought to you by:
theller
From: Sebastian M. E. <er...@pl...> - 2018-03-21 16:00:28
|
Hi all, I have been working on something, well, a little crazy. It's getting to a pointer where I'd like to actively seek external input from potential users as well as experienced ctypes developers. I hope that this is the right place to look for them. The topic of "somehow" calling a function in a Windows DLL on Linux / OS X / BSD pops up quite frequently. I had to do this many times, which made me develop a number of ugly Python scripts. All of them were using some remote procedure call mechanism between a Unix process and a Wine process. From my perspective, it was the lesser evil compared to writing an full-blown winelib-application around the DLLs. At some point, I decided to consolidate my scripts into a generic Python module, designed as a ctypes drop-in-replacement, hiding all the required plumbing from the user. Meet "zugbruecke": https://github.com/pleiszenburg/zugbruecke If you you're on some Unix-like system and if you have Python and Wine installed, I guess the most simple thing you can do with it is this: import zugbruecke as 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)) You have just witnessed "msvcrt.dll" (Wine's implementation of the MS visual C/C++ runtime library) in action on Unix. Under the hood, zugbruecke automatically spins up a Windows version of Python on top of Wine, which uses the actual ctypes module for calling into the DLL. Subsequently, zugbruecke takes care of shipping arguments and return values back and forth as well as keeping memory in sync. What works: All fundamental data types and pointers to them, structure types, pointers pointing to arbitrary sections of memory (if you can provide a hint on their length) and call back functions / function pointers (with significant limitations, though). What does not work: Plenty of edge cases I probably have not thought of, among "a few" other things. See issue tracker on GitHub. The projects goal is to create a module, which behaves exactly like ctypes would on Windows. Well aware of the limitations of the chosen technical approach, it is intentionally written as a "quick and dirty" solution to a common problem. It is, by no means, meant as a professional alternative to writing a winelib-application, if one heavily relies on a Windows DLL / application on Unix. The current development status is ALPHA and some of the code is of clearly questionable quality. So be careful if you're interesting in actually using the module. I have been using it in production code for numerical applications for a while now, but I also keep verifying and double-checking my results. I'd love to see comments, suggestions, test reports, bug reports or [slating] code reviews. Thanks, Sebastian |