[Mono-bugs] [Bug 42021][Wis] New - DllImport/PInvoke does not deal correctly with A/W versions of functions.

bugzilla-daemon@rocky.ximian.com bugzilla-daemon@rocky.ximian.com
Mon, 28 Apr 2003 10:43:44 -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 japj@darius.demon.nl.

http://bugzilla.ximian.com/show_bug.cgi?id=42021

--- shadow/42021	Mon Apr 28 10:43:44 2003
+++ shadow/42021.tmp.23116	Mon Apr 28 10:43:44 2003
@@ -0,0 +1,71 @@
+Bug#: 42021
+Product: Mono/Runtime
+Version: unspecified
+OS: 
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Wishlist
+Component: misc
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: japj@darius.demon.nl               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: DllImport/PInvoke does not deal correctly with A/W versions of functions.
+
+DllImport/PInvoke does not deal correctly with A/W versions of functions.
+
+During SWT-win32 tests with mono on windows, it was observed that some
+functions can not be found by PInvoke in the windows dlls
+
+I had a look at the .NET Framework SDK documentation and apparently the
+CharSet Object Field influences the way PInvoke should work.
+
+Summary from the docs:
+
+Some APIs export two versions of functions that take string arguments:
+narrow (ANSI) and wide (Unicode). The Win32 API, for instance, includes the
+following entry-point names for the MessageBox function: 
+
+MessageBoxA 
+Provides 1-Byte character ANSI formatting, distinguished by an "A"
+appending the entry-point name. Calls to MessageBoxA always marshal strings
+in ANSI format, as is common on Window 95 and Windows 98 platforms. 
+
+MessageBoxW 
+Provides 2-Byte character Unicode formatting, distinguished by a "W"
+appending the entry-point name. Calls to MessageBoxW always marshal strings
+in Unicode format, as is common on Window NT and Windows 2000 platforms. 
+
+
+CharSet.Ansi (default value) 
+Platform invoke marshals strings from their managed format (Unicode) to
+ANSI format. 
+
+When the ExactSpelling object field is False, as it is by default in the
+Managed Extensions for C++ and C#, platform invoke searches for the
+unmangled name first (MessageBox), then the mangled name (MessageBoxA) if
+the unmangled name is not found. If a DLL contains both MessageBox and
+MessageBoxA, platform invoke selects MessageBoxA. Notice that ANSI
+name-matching behavior differs from Unicode name-matching behavior. 
+
+CharSet.Unicode 
+Platform invoke copies strings from their managed format (Unicode) to
+Unicode format. 
+
+When the ExactSpelling object field is False, as it is by default in the
+Managed Extensions for C++ and C#, platform invoke searches for the mangled
+name first (MessageBoxW), then the unmangled name (MessageBox) if the
+unmangled name is not found. If a DLL contains both MessageBox and
+MessageBoxW, platform invoke selects MessageBoxW. Notice that Unicode
+name-matching behavior differs from ANSI name-matching behavior. 
+
+CharSet.Auto 
+Platform invoke chooses between ANSI and Unicode formats at runtime, based
+on the target platform.
+
+So this functionality is probably missing in mono and explains why certain
+SWT constructs work ok in MS .NET but not in Mono.