How to import a C# dll to python -


i've got third party c# dll has been created in dot net 4.5 , has platform target of x86. import python script , i've started off rob deary's answer here. can't example work. i'm using python version 2.7.6 , attributeerror shown below.

file "c:\python27\lib\ctypes\__init__.py", line 378, in __getattr__     func = self.__getitem__(name) file "c:\python27\lib\ctypes\__init__.py", line 383, in __getitem__     func = self._funcptr((name_or_ordinal, self)) attributeerror: function 'add' not found 

please note aware of ironpython , python dot net need working c python. here's sample code generates custom c# library: classlibrary1.dll

using system; using system.runtime.interopservices; using rgiesecke.dllexport;  class test {     [dllexport("add", callingconvention = callingconvention.cdecl)]     public static int testexport(int a, int b)     {         return + b;     } } 

and here's python script generates error

import ctypes lib = ctypes.cdll.loadlibrary('classlibrary1.dll') lib.add(3,5) 

when use line below, output get. @ least know loading dll, i'm not sure why function can't found.

>>> lib.__dict__ {'_funcptr': <class 'ctypes._funcptr'>, '_handle': 254476288, '_name': 'classlibrary1.dll'} >>> 

any appreciated. thanks

as rgiesecke.dllexport documentation states, need target specific architecture (x86 or x64) when building code. leaving set cpu (the default) not work.


Comments

Popular posts from this blog

html - Difficulties with background-image property -

visual studio code - What does the isShellCommand property actually do and how should you use it? -

ios - Segue not passing data between ViewControllers -