[IronPython] how to convert C# MarshalAs code to IronPython

Ashley Abraham abrahams84 at gmail.com
Mon Jun 7 18:42:43 CEST 2010


I'll try the ctypes... thanks for pointing me in the right direction and
your help is much appreciated.

Ash

On Mon, Jun 7, 2010 at 10:02 AM, Jeff Hardy <jdhardy at gmail.com> wrote:

> On Sun, Jun 6, 2010 at 8:20 PM, Ashley Abraham <abrahams84 at gmail.com>
> wrote:
> > Jeff,
> >     I think I miss read your reply, what you are saying is that if it
> based
> > on ctypes it will work in IronPython as well is it?? I thought you needed
> > IronClad and so on make it work.
>
> Yeah, with ctypes IronPython can call native code directly - it
> actually uses P/Invoke behind the scenes to do it. Python also
> implements ctypes, as do Jython and PyPy, so any code that you write
> using ctypes should work on any Python implementation.
>
> I haven't tested this (seeing as I don't have the exact DLL) but it
> should be pretty close:
>
> from ctypes import *
> vniwave = CDLL('vniwave.dll')
>
> cwavec = vniwave.cwavec
> cwavec.restype = c_int
> cwavec.argtypes = [c_int, c_int, POINTER(c_char_p)]
>
> The only part I'm not sure about is the string[] - I'm assuming the C
> function takes a char**.
>
> Alternatively, you could write the P/Invoke declarations in a C# class
> library and load that into IronPython using clr.AddReference, but I'd
> recommend using ctypes.
>
> - Jeff
> _______________________________________________
> 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/20100607/ed55c8bb/attachment.html>


More information about the Ironpython-users mailing list