Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Windows DLL from Linux

Tags:

We need to interface to 3rd party app, but company behind the app doesn't disclose message protocol and provides only Windows DLL to interface to.

Our application is Linux-based so I cannot directly communicate with DLL. I couldn't find any existing solution so I'm considering writing socket-based bridge between Linux and Windows, however I'm sure it is not such a unique problem and somebody should have done it before.

Are you aware of any solution that allows to call Windows DDL functions from C app on Linux? It can use Wine or separate Windows PC - doesn't matter.

Many thanks in advance.

like image 628
qrdl Avatar asked Dec 17 '08 10:12

qrdl


People also ask

Can you use Windows DLL on Linux?

A Google researcher has been developing "LoadLibrary" as a means of being able to load Windows Dynamic Link Libraries (DLLs) that in turn can be used by native Linux code.

Can we run DLL file in Linux?

Normal DLL files are Windows' linked libraries, so they cannot run on Linux directly, however it's possible to compile DLL files specifically for Linux using . NET Core.

How do I open a DLL file in Linux?

If you are using Windows 7 or newer, open the folder containing the new DLL file, hold the Shift key and right-click in the folder, and select "Open command window here". The Command Prompt will open directly to that folder. Type regsvr32 dllname . dll and press Enter.

Can Wine run DLL files?

Wine also installs DLLs into this directory. Some applications actually open these files directly and expect them to be valid Windows DLLs. However, Wine does not actually use the DLL file format for most of its own libraries.


1 Answers

I wrote a small Python module for calling into Windows DLLs from Python on Linux. It is based on IPC between a regular Linux/Unix Python process and a Wine-based Python process. Because I have needed it in too many different use-cases / scenarios myself, I designed it as a "generic" ctypes module drop-in replacement, which does most of the required plumbing automatically in the background.

Example: Assume you're in Python on Linux, you have Wine installed, and you want to call into msvcrt.dll (the Microsoft C runtime library). You can do the following:

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)) 

Source code (LGPL), PyPI package & documentation.

It's still a bit rough around the edges (i.e. alpha and insecure), but it does handle most types of parameters (including pointers).

like image 67
s-m-e Avatar answered Sep 21 '22 18:09

s-m-e