[Mono-bugs] [Bug 56965][Cri] New - P/Invoke is marshalling string arrays as UTF-8 not Unicode

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Tue, 13 Apr 2004 19:24:31 -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 cscholes@novell.com.


--- shadow/56965	2004-04-13 19:24:30.000000000 -0400
+++ shadow/56965.tmp.4801	2004-04-13 19:24:31.000000000 -0400
@@ -0,0 +1,61 @@
+Bug#: 56965
+Product: Mono: Runtime
+Version: unspecified
+OS: SUSE 9.0
+OS Details: Also happens on Windows XP
+Status: NEW   
+Priority: Critical
+Component: misc
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: cscholes@novell.com               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+Summary: P/Invoke is marshalling string arrays as UTF-8 not Unicode
+Description of Problem:
+I am trying to pass an array of strings from a managed program to an
+unmanaged DLL.  The array of strings is being Marshalled as UTF-8 not
+Unicode.  If I pass just a string then it is Marshalled as Unicode but when
+I change it to an array of strings its Marshalled as UTF-8.
+My managed function is defined as:
+[DllImport("unidll", CharSet = CharSet.Unicode, CallingConvention =
+public static extern void nativePrintString(string[] str, int size);
+My unmanaged function is defined as:
+extern "C" void nativePrintString(unsigned short **str, int size)
+Steps to reproduce the problem:
+1. Create an array of strings like:
+char[] chars = {'\u65E0','\u6548','\u67E5','\u8BE2','\u4E32','\u0041'};
+string ustr = new string(chars);
+string[] ustrings = {ustr, "this", "is", "it"};
+2. pass the array of strings to an unmanaged dll
+3. Look at result and find that the characters have been converted to UTF-8
+Actual Results:
+UTF-8 bytes (E6, 97, A0, E6, 95, 88, E6, 9F, A5, E8, AF, A2, E4, B8, B2,
+41) for first chinese string.
+Expected Results:
+Unicode bytes (E0, 65, 48, 65, E5, 67 E2, 8B, 32, 4E, 41, 0) for first
+chinese string
+How often does this happen? 
+Additional Information:
+I am using Mono .31.  This happens on Linux (SUSE 9) or Windows (XP)