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

Curt Hagenlocher curt at hagenlocher.org
Thu Jul 31 20:21:04 CEST 2008

It wouldn't be sufficient to recompile with /clr.  When you do that, your
classes don't automatically become managed classes.  You would still need to
either modify your classes or to create wrappers using C++/CLI (
http://en.wikipedia.org/wiki/C%2B%2B/CLI).  In order for a C++ class to be
visible to IronPython, it would need to be declared as a "ref class" -- you
can see more about that at the referenced Wikipedia article.

On Thu, Jul 31, 2008 at 9:22 AM, Anders Elfgren <
anders.elfgren at avalanchestudios.se> wrote:

>  Hi,
> 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. :)
> /Anders
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20080731/b5364b48/attachment.html>

More information about the Ironpython-users mailing list