[Mono-bugs] [Bug 80426][Wis] New - Problem with interop and wide strings (narrow strings are ok)

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Tue Jan 2 11:34:43 EST 2007

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 dan.maser at inin.com.


--- shadow/80426	2007-01-02 11:34:43.000000000 -0500
+++ shadow/80426.tmp.6016	2007-01-02 11:34:43.000000000 -0500
@@ -0,0 +1,62 @@
+Bug#: 80426
+Product: Mono: Class Libraries
+Version: 1.2
+OS Details: RHEL kernel 2.6.9-42 on i686
+Status: NEW   
+Priority: Wishlist
+Component: System
+AssignedTo: mono-bugs at ximian.com                            
+ReportedBy: Dan.Maser at inin.com               
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+Summary: Problem with interop and wide strings (narrow strings are ok)
+Please fill in this template when reporting a bug, unless you know what you
+are doing.
+Description of Problem:
+I have a C++ shared lib that exports a function with this declaration:
+    extern "C" __attribute__((stdcall)) void foo(const char* myParam);
+and I have a C# program compiled with gmcs which declares it like this:
+    [DllImport("myLib.so", CallingConvention=CallingConvention.StdCall)]
+    public static extern void foo([MarshalAs(UnmanagedType.LPStr)] String
+If I invoke the foo function in C# with the string "Hello" it works
+properly and the bytes that get sent to the C++ function are
+0x48,0x65,0x6c,0x6c,0x6f,0x00 as expected.  
+However, if I change the MarshalAs type to UnmanagedType.LPWStr and change
+the C++ dll to accept a wchar_t* instead of a char*, the bytes do not come
+across properly - the bytes still arrive the same as if the mono were
+sending a narrow string.  Also, if I add to the DllImport attributes
+'CharSet=CharSet.Unicode' that doesn't make a difference either, the
+strings are still comming through as the same narrow strings.
+Steps to reproduce the problem:
+1. See above.  Simple invoke an exported C++ shared lib function using wide
+Actual Results:
+  Bytes are always passed to the C++ lib as narrow strings regardless of
+the attributes listed in C#
+Expected Results:
+  Bytes are passed to the C++ lib as wide strings or narrow strings as per
+the DllImport attributes
+How often does this happen? 
+  Each time
+Additional Information:

More information about the mono-bugs mailing list