[IronPython] [python] importing C Based *.dlls

Michael Foord fuzzyman at voidspace.org.uk
Fri Dec 14 13:51:14 CET 2007

Kaveripakam, Sathish wrote:
> I am trying to "import C-Based dll's" into the Iron python files using 
> import function, wherein I have path to the Standard C-python 
> libraries is added.
> Ex:
> import sys
> import os
> if __name__ == "__main__":
> sys.path.append("C:/IronPython/IronPythonBinary-V1.1/IronPython-1.1-Bin/IronPython-1.1/Tutorial")
>   import clr
> clr.AddReferenceToFileAndPath("C:/IronPython/IronPythonBinary-V1.1/IronPython-1.1-Bin/IronPython-1.1/Tutorial/csextend.dll")
>   import Simple as t_Simple
>   import c_dll 
> In the above file I am able to import the C# file , but when execution 
> comes to c_dll, it complains as "No module named c_dll".
> Can anyone let me know, if the C based dll's can be imported in Iron 
> python environment ? If not, any work arounds available for the fix ?

The *basic* situation is that C based DLLs can't be imported into 

Are they CPython C extensions? There is a way (experimental) to access 


In general C libraries (unmanaged code) can be used from .NET with 
'Platform Invoke' - using the DllImport attribute. Unfortunately 
attributes can't be accessed from IronPython so you will need some stub 
C# to do this. You can generate the C# dynamically from IronPython. 
These two articles may help:


Michael Foord

> Regards
> ------------------------------------------------------------------------
> _Legal Notice:_
> The information in this electronic transmission may contain 
> confidential or legally privileged information and is intended solely 
> for the individual(s) named above. If you are not an intended 
> recipient or an authorized agent, you are hereby notified that 
> reading, distributing, or otherwise disseminating, copying or taking 
> any action based on the contents of this transmission is strictly 
> prohibited. Any unauthorized interception of this transmission is 
> illegal under law. If you have received this transmission in error, 
> please notify the sender by telephone [at the number indicated 
> above/on +41 58 928 0101] as soon as possible and then destroy all 
> copies of this transmission. 
> ------------------------------------------------------------------------
> ------------------------------------------------------------------------
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

More information about the Ironpython-users mailing list