I have several .dll files with classes designed to control an external device connected to my desktop via ethernet. I would like to import these classes in python and use their member functions / variables, etc. To control the device.
I looked through several options, including:
-ctypes (which seemed to work well for functions, but not for classes). Here, “DotNet \ Aerotech.Ensemble.dll” is my dll library, and “Network” is a class in this library with a “Connect” member function. The library is loading, but I cannot access the class ...
>>> from ctypes import * >>> lib = cdll.LoadLibrary('DotNet\Aerotech.Ensemble.dll') >>> lib.Network.Connect() Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Python26\lib\ctypes\__init__.py", line 366, in __getattr__ func = self.__getitem__(name) File "C:\Python26\lib\ctypes\__init__.py", line 371, in __getitem__ func = self._FuncPtr((name_or_ordinal, self)) AttributeError: function 'Network' not found
-IronPython / Python for .Net, but they seem to be separate languages in general, and I want to be able to do everything from one place (python).
-SWIG. The SWIG documentation seems to indicate that it can handle import classes, but it also seems to require that the C ++ code files and header files (which I didn't have) are wrapped for use as a python module.
I'm a beginner and pretty lost here, so any help is appreciated!
EDIT:
@SvenMarnach: I looked at IronPython and was able to get it to work with my DLL files, but I want to do it in Python, since I already do a lot of things in this language. I want to integrate these DLL functions or classes or something into existing python programs.
However, when working with IronPython, I came across
Python for .NET , which claims to be able to set a .Net alert on an existing installation python ... This works (i.e. I can access the DLL files and manage my device), if I use it in the directory where I downloaded python for .NET files, but if I try it in some other directory (remembering to add python.net dir to sys.path), you get an error
ImportError: dynamic module does not define init function (initclr)