Using Python to Access Methods From C# Library - Interop .dll File
Question: I have a .dll file (with "Interop." prefix) containing a library written in
C#. Within the library is a class, several enums, several interfaces, and
several delgates. (Observed by decompiling the .dll with JetBrains dotPeek)

See the dll structure here:
![DllStructure](http://i.stack.imgur.com/4JMVk.png)

I need to use pure Python to access the methods within the class. I have
tried:

    
    
    from ctypes import *
    name = "Interop.HTBRAILLEDRIVERSERVERLib.dll"
    mydll = cdll.LoadLibrary(name)
    

However attempting to call any of the methods contained in the class
"HtBrailleDriverClass" leads to "AttributeError: function 'initialize' not
found". I have also attempted to access them from their ordinal indexes:

    
    
    print mydll[1]
    

However this gives the error "AttributeError: function ordinal 1 not found".

Is anyone able to shed light on why I am unable to access the class within
this .dll and why I cannot access any of the methods either?

Please bear in mind I must use pure Python.


Answer: You can use python.net to access it

    
    
    import clr,sys
    sys.path.append("path of your dll")
    clr.AddReference("YourDllName")
    import YourDllName
    

Then Try printing any value of member of your class like

    
    
    print YourDllName.ClassName.Member
    

from your python script

**Note : Your need to put clr.pyd and python.runtime.dll inside your**

**Python27/Dlls folder**

If You don't want to append your dll path then put the dll inside the
python2.x/Lib/site-packages folder . Then u can avoid 2nd line -
sys.path.append() too .

