[IronPython] Using a c library as a dll or assembly

Srivatsn Narayanan srivatsn at microsoft.com
Thu Jul 31 18:26:13 CEST 2008

Did you add a reference to the dll before importing it - like this:

import clr

From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Anders Elfgren
Sent: Thursday, July 31, 2008 9:22 AM
To: users at lists.ironpython.com
Subject: [IronPython] Using a c library as a dll or assembly


First let me say that I'm new to Iron Python, but at least I've read this in the FAQ.. :)

Q: How do I build and call into PYD libraries?
A: IronPython does not support using PYDs built for CPython since they leverage implementation details of CPython.  You can get a similar effect for new "PYD"s you would like to implement by writing them in C# or VB and building a DLL for .NET.

That said, I've got some questions to see if what I'm doing is possible anyway.

We've got a c library of which most of the code has also been written in Python. We want to create an editor using .net forms which we can use to edit some files, and to do that we need some data structures that exist in this library.

My current idea is to interface against the python library using IronPython, and then accessing the datastructures through that in C# (although if absolutely necessary, we could write the editor in IronPython too). The thing that is standing against me now is that one function that exists a small C dll. Since IronPython can't access this (unless this has changed since the FAQ was written?), I was thinking that maybe I can compile the dll using the /clr flag and thus get a .net assembly. Would I then be able to use the function?

The Python code just tries to import it:
import AvHash

And then use it..
def AdfHash(str):
    return AvHash.HashString(str)

At the import statement, this error is raised:
Traceback (most recent call last):
  File X:\ctg\libs\ADF\main\common\modeditor.ipy, line 20, in Initialize
  File , line 0, in __import__##4
  File X:\ctg\libs\ADF\main\common\AdfLib.py, line 1, in Initialize
  File , line 0, in __import__##4
ImportError: No module named AvHash

Or is there some other solution? I've just started researching how to interface between C/C#/Python/IronPython so there may well be things I haven't heard of...
I hope I've made my problem clear, thanks for any responses. :)


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20080731/37742ab0/attachment.html>

More information about the Ironpython-users mailing list