[Mono-list] Need help with DllImport (P/Invoke) and UCS-4 unicode

Jonathan Chambers joncham at gmail.com
Sun Jul 15 22:24:40 EDT 2007

Hello Christian,
     I had the same problem in a different setting. I use a custom
marshaller (http://msdn2.microsoft.com/en-us/library/d3cxf9f0.aspx) for
strings in all of my pinvokes. It's pretty straightforward setting up a
custom marshaller if you follow the link above. If you need more details let
me know.


On 7/15/07, Christian Heimes <lists at cheimes.de> wrote:
> Hello!
> I'm working on PythonNet (http://pythonnet.sourceforge.net/). PythonNet
> is an integration of the C library into .NET which allows a developer to
> use .NET code inside Python or Python inside .NET. In the past few weeks
> I've fixed a bunch of outstanding bugs and ported PythonNet to Python
> 2.5. It works pretty well on Windows.
> However Linux with mono is a different story. Under Windows Python is
> using a UCS-2 to store unicode but most Linux distributions (Debian,
> Ubuntu and probably Redhat and SuSE) are compiling Python with UCS-4.
> .NET supports only 2 byte unicode. My problem is perfectly explain at
> http://www.mono-project.com/Interop_with_Native_Libraries#P.2FInvoke_Specification
> One of the problematic function look like:
>     [DllImport(Runtime.dll, CallingConvention = CallingConvention.Cdecl,
>            EntryPoint = "PyUnicodeUCS4_FromUnicode",
>            ExactSpelling = true, CharSet = CharSet.Unicode)]
>     internal unsafe static extern IntPtr
>     PyUnicode_FromUnicode(string s, int size);
> More functions can be found at
> https://pythonnet.svn.sourceforge.net/svnroot/pythonnet/branches/clr-2.0-python-2.5-branch/src/runtime/runtime.cs
> How should I solve the issue? Has Mono some generic solution for the
> general issue of UCS-4 vs. UCS-2 unicode or do I have to convert the
> stuff manually by wrapping every external method? If I have to convert
> it manually is System.Text.Encoding.UTF32 the right module?
> Christian
> _______________________________________________
> Mono-list maillist  -  Mono-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-list/attachments/20070715/466e47e6/attachment.html 

More information about the Mono-list mailing list