[Mono-bugs] [Bug 543133] New: P/Invoke fails for out StringBuilder parameter, wrapping .dll with unicode string
bugzilla_noreply at novell.com
bugzilla_noreply at novell.com
Wed Sep 30 07:24:26 EDT 2009
http://bugzilla.novell.com/show_bug.cgi?id=543133
Summary: P/Invoke fails for out StringBuilder parameter,
wrapping .dll with unicode string
Classification: Mono
Product: Mono: Runtime
Version: 2.4.x
Platform: 32bit
OS/Version: Windows XP
Status: NEW
Severity: Minor
Priority: P5 - None
Component: interop
AssignedTo: mono-bugs at lists.ximian.com
ReportedBy: giorgio.tino at gmail.com
QAContact: mono-bugs at lists.ximian.com
Found By: ---
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US)
AppleWebKit/532.0 (KHTML, like Gecko) Chrome/3.0.195.21 Safari/532.0
I'm trying to write a method to wrap a native .dll function. Function signature
is something like that:
#define MY_EXPORT blah blah blah
#define MY_RESULT int
#define OUT
#define IN
// A lot of other stuff
MY_EXPORT MY_RESULT my_get_name(OUT unsigned short **name);
the 'name' is a UNICODE string (array of 16bit unicode chars).
The following marshalling DOES NOT work in Mono but works in .NET:
[DllImport("MyLibrary.dll", EntryPoint = "my_get_name")]
public static extern Int32 MyGetName(out StringBuilder name);
this is how I call the method:
StringBuilder name;
Int32 result = MyGetName(out name);
this is the error I get when executing the code:
**
ERROR:marshal.c:6929:emit_marshal_object: assertion failed: (!t->byref)
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
Since it works in .NET but not in Mono, I assume it can be a Mono issue.
Maybe this this is not the correct way of marshalling this kind of data, but is
it correct that mono crashes?
BTW the following marshalling works OK:
[DllImport("MyLibrary.dll", EntryPoint = "my_get_name")]
public static extern Int32 MyGetName(out IntPtr name);
this is how I call the method:
IntPtr pName;
Int32 result = MyGetName(out pName);
string name = Marshal.PtrToStringUni(pName);
Reproducible: Always
Steps to Reproduce:
1. P/Invoke of MY_EXPORT MY_RESULT my_get_name(OUT unsigned short **name) as
[DllImport("MyLibrary.dll", EntryPoint = "my_get_name")]
public static extern Int32 MyGetName(out StringBuilder name);
2. StringBuilder name;
Int32 result = MyGetName(out name);
Actual Results:
**
ERROR:marshal.c:6929:emit_marshal_object: assertion failed: (!t->byref)
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
Expected Results:
StringBuffer contains the requested unicode string
--
Configure bugmail: http://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.
More information about the mono-bugs
mailing list