2

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

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.

1
  • did you try using Python for .NET (Python.NET)? ctypes cannot load .NET assemblies. Commented Jan 11, 2015 at 2:47

1 Answer 1

3

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 .

Sign up to request clarification or add additional context in comments.

2 Comments

I tried this. I'm getting the following error: AttributeError: module 'clr' has no attribute 'AddReference'
Could you please paste the line of code which you tried , also Is import clr works on python shell. . ??

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.