[Mono-bugs] [Bug 50116][Wis] Changed - Marshaling/PInvoke bug?
bugzilla-daemon@bugzilla.ximian.com
bugzilla-daemon@bugzilla.ximian.com
Sat, 25 Oct 2003 22:10:45 -0400 (EDT)
Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.
Changed by pbaena@uol.com.ar.
http://bugzilla.ximian.com/show_bug.cgi?id=50116
--- shadow/50116 2003-10-25 16:19:00.000000000 -0400
+++ shadow/50116.tmp.5013 2003-10-25 22:10:45.000000000 -0400
@@ -1,13 +1,13 @@
Bug#: 50116
Product: Mono/Runtime
Version: unspecified
OS: other
OS Details: Debian Sid
-Status: RESOLVED
-Resolution: FIXED
+Status: REOPENED
+Resolution:
Severity: Unknown
Priority: Wishlist
Component: misc
AssignedTo: mono-bugs@ximian.com
ReportedBy: pbaena@uol.com.ar
QAContact: mono-bugs@ximian.com
@@ -145,6 +145,94 @@
implemented at all, so the runtime simply passed the managed array
to the unmanaged code, without any copying.
+
+------- Additional Comments From pbaena@uol.com.ar 2003-10-25 22:10 -------
+I changed a few things according to your and Jonathan Pryor advice,
+but it still isn't working.
+
+--------------------------------------CODE--------------------------
+using System;
+using System.Runtime.InteropServices;
+
+class testbug {
+
+public const string GLIB_LIBRARY = "glib-2.0";
+public const string STRLEN_LIBRARY = "pango-1.0";
+public const string MEMMOVE_LIBRARY = "gtk-x11-2.0";
+
+[DllImport(GLIB_LIBRARY, CharSet = CharSet.Unicode)]
+public static extern IntPtr g_utf16_to_utf8(char[] str, int len, out
+int items_read, out int items_written, IntPtr error);
+[DllImport(GLIB_LIBRARY, CharSet = CharSet.Unicode)]
+public static extern IntPtr g_utf8_to_utf16(byte[] str, int len, out
+int items_read, out int items_written, IntPtr error);
+
+[DllImport(STRLEN_LIBRARY, CharSet = CharSet.Unicode)]
+public static extern int strlen(IntPtr str);
+
+[DllImport(MEMMOVE_LIBRARY, CharSet = CharSet.Unicode)]
+public static extern void memmove(IntPtr dest, [In, Out] byte[] src,
+int size);
+[DllImport(MEMMOVE_LIBRARY, CharSet = CharSet.Unicode)]
+public static extern void memmove([In, Out] byte[] dest, IntPtr src,
+int size);
+[DllImport(MEMMOVE_LIBRARY, CharSet = CharSet.Unicode)]
+public static extern void memmove([In, Out] char[] dest, IntPtr src,
+int size);
+
+[DllImport(GLIB_LIBRARY, CharSet = CharSet.Unicode)]
+public static extern void g_free(IntPtr mem);
+[DllImport(GLIB_LIBRARY, CharSet = CharSet.Unicode)]
+public static extern IntPtr g_malloc(int size);
+
+
+[DllImport(GLIB_LIBRARY, CharSet = CharSet.Unicode)]
+public static extern IntPtr g_list_append(IntPtr list, IntPtr data);
+[DllImport(GLIB_LIBRARY, CharSet = CharSet.Unicode)]
+public static extern IntPtr g_list_nth_data(IntPtr list, int n);
+
+public static void Main ()
+{
+ string str = "Let's i18n, baby...do it hard!";
+ IntPtr glist = IntPtr.Zero;
+ bool terminate = true;
+ char [] strchar = str.ToCharArray();
+
+ int read, written;
+ IntPtr ptr = g_utf16_to_utf8 (strchar, str.Length, out read,
+out written, IntPtr.Zero);
+
+ if (read != strchar.Length) written++;
+ byte [] buffer = new byte [written + (terminate ? 1 : 0)];
+ memmove (buffer, ptr, written);
+ g_free (ptr);
+
+ IntPtr data = g_malloc (buffer.Length);
+ memmove (data, buffer, buffer.Length);
+ glist = g_list_append (glist, data);
+
+ data = g_list_nth_data (glist, 0);
+ int length = strlen (data);
+
+ byte [] buffer1 = new byte [length];
+ memmove (buffer1, data, length);
+
+ ptr = g_utf8_to_utf16 (buffer1, buffer1.Length, out read, out
+written, IntPtr.Zero);
+
+ char [] chars = new char [written];
+ memmove (chars, ptr, written * 2);
+
+ Console.WriteLine (chars);
+
+ g_free (ptr);
+}
+
+}
+-----------------------------------------------------------------
+
+Sorry if I made another mistake.
+Pablo