How to load c # dll in python?

how can i load c # dll in python?

Should I add extra code to C # files? (e.g. export to C ++ files)

I do not want to use IronPython. I want to import a module in Python!

+19
python c # cpython
Jan 16
source share
4 answers

This is the answer to the second part of your question. Try to make the COM DLL visible.

using

[ComVisible(true)] 

Ok IronPython is a .net implementation of the Python language. Technology will use DLR.net 4.0 when it arrives, so IronPython will have more dynamism (this word). (In English, if you are a Python guru, you will feel at home when using IronPython)

So, you can choose IronPython, if you do, you can skip the visible part of COM. Since both (C #, Iron Python) are under .Net

http://ironpython.net/

Visit here the C # DLL example that is visible for COM

+4
Jan 16 '10 at 15:40
source share

The Python package for .NET and the Python IronPython implementation now work the same.

Example for C # DLL MyDll.dll :

 import clr clr.AddReference('MyDll') from MyNamespace import MyClass my_instance = MyClass() 

See this post for more details.

+21
Nov 28 '13 at 10:26
source share

Python for .NET works well if you do not want to use IronPython.

+5
Jul 18 '13 at 22:02
source share

If you do not want to use solutions such as Python.NET or IronPython, you can implement the C ++ / CLI shell and use the Pythons types to load. For example:

C ++ / CLI Library CallCSharp:

 extern "C" { __declspec(dllexport) void foo() { // here you could use managed and unmanaged code Console.WriteLine("Hello, C# world..."); } 

Python script:

 from ctypes import cdll lib = cdll.LoadLibrary("./CallCSharp.dll") lib.foo() 

I highly recommend reading this blog: http://pragmateek.com/if-your-plumbing-doesnt-work-youre-just-not-using-enough-pipes/#more-1745

It also handles the problem that occurs when the C ++ / CLI shell calls code that is in a different assembly (then you get something like WindowsError: [Error -532462766] Windows error 0xE0434352 from your Python script).

+2
Mar 21 '17 at 15:06
source share



All Articles