4 // Tests for native->managed marshalling
8 using System
.Runtime
.InteropServices
;
12 [StructLayout (LayoutKind
.Sequential
)]
13 public struct SimpleStruct
{
18 [MarshalAs(UnmanagedType
.LPWStr
)]
22 [StructLayout (LayoutKind
.Sequential
)]
23 public class SimpleClass
{
30 public static SimpleStruct
delegate_test_struct (SimpleStruct ss
)
37 res
.d
= ss
.d
+ "-RES";
38 res
.d2
= ss
.d2
+ "-RES";
43 public static int delegate_test_struct_byref (int a
, ref SimpleStruct ss
, int b
)
45 if (a
== 1 && b
== 2 && ss
.a
&& !ss
.b
&& ss
.c
&& ss
.d
== "TEST2") {
56 public static int delegate_test_struct_out (int a
, out SimpleStruct ss
, int b
)
67 public static SimpleClass
delegate_test_class (SimpleClass ss
)
72 if (! (!ss
.a
&& ss
.b
&& !ss
.c
&& ss
.d
== "TEST"))
80 public static int delegate_test_class_byref (ref SimpleClass ss
)
85 if (!ss
.a
&& ss
.b
&& !ss
.c
&& ss
.d
== "TEST") {
97 public static int delegate_test_class_out (out SimpleClass ss
)
99 ss
= new SimpleClass ();
108 public static int delegate_test_primitive_byref (ref int i
)
117 public static int delegate_test_string_marshalling (string s
)
119 return s
== "ABC" ? 0 : 1;
122 [DllImport ("libtest", EntryPoint
="mono_test_ref_vtype")]
123 public static extern int mono_test_ref_vtype (int a
, ref SimpleStruct ss
, int b
, TestDelegate d
);
125 public delegate int OutStructDelegate (int a
, out SimpleStruct ss
, int b
);
127 [DllImport ("libtest", EntryPoint
="mono_test_marshal_out_struct")]
128 public static extern int mono_test_marshal_out_struct (int a
, out SimpleStruct ss
, int b
, OutStructDelegate d
);
130 [DllImport ("libtest", EntryPoint
="mono_test_marshal_delegate2")]
131 public static extern int mono_test_marshal_delegate2 (SimpleDelegate2 d
);
133 [DllImport ("libtest", EntryPoint
="mono_test_marshal_delegate4")]
134 public static extern int mono_test_marshal_delegate4 (SimpleDelegate4 d
);
136 [DllImport ("libtest", EntryPoint
="mono_test_marshal_delegate5")]
137 public static extern int mono_test_marshal_delegate5 (SimpleDelegate5 d
);
139 [DllImport ("libtest", EntryPoint
="mono_test_marshal_delegate6")]
140 public static extern int mono_test_marshal_delegate6 (SimpleDelegate5 d
);
142 [DllImport ("libtest", EntryPoint
="mono_test_marshal_delegate7")]
143 public static extern int mono_test_marshal_delegate7 (SimpleDelegate7 d
);
145 [DllImport ("libtest", EntryPoint
="mono_test_marshal_delegate8", CharSet
=CharSet
.Unicode
)]
146 public static extern int mono_test_marshal_delegate8 (SimpleDelegate8 d
, string s
);
148 [DllImport ("libtest", EntryPoint
="mono_test_marshal_delegate9")]
149 public static extern int mono_test_marshal_delegate9 (SimpleDelegate9 d
, return_int_delegate d2
);
151 [DllImport ("libtest", EntryPoint
="mono_test_marshal_delegate10")]
152 public static extern int mono_test_marshal_delegate10 (SimpleDelegate9 d
);
154 [DllImport ("libtest", EntryPoint
="mono_test_marshal_primitive_byref_delegate")]
155 public static extern int mono_test_marshal_primitive_byref_delegate (PrimitiveByrefDelegate d
);
157 [DllImport ("libtest", EntryPoint
="mono_test_marshal_return_delegate_delegate")]
158 public static extern int mono_test_marshal_return_delegate_delegate (ReturnDelegateDelegate d
);
160 public delegate int TestDelegate (int a
, ref SimpleStruct ss
, int b
);
162 public delegate SimpleStruct
SimpleDelegate2 (SimpleStruct ss
);
164 public delegate SimpleClass
SimpleDelegate4 (SimpleClass ss
);
166 public delegate int SimpleDelegate5 (ref SimpleClass ss
);
168 public delegate int SimpleDelegate7 (out SimpleClass ss
);
170 public delegate int SimpleDelegate8 ([MarshalAs (UnmanagedType
.LPWStr
)] string s1
);
172 public delegate int return_int_delegate (int i
);
174 public delegate int SimpleDelegate9 (return_int_delegate del
);
176 public delegate int PrimitiveByrefDelegate (ref int i
);
178 public delegate return_int_delegate
ReturnDelegateDelegate ();
180 public static int Main () {
181 return TestDriver
.RunTests (typeof (Tests
));
184 /* Test structures as arguments and return values of delegates */
185 public static int test_0_marshal_struct_delegate () {
186 SimpleDelegate2 d
= new SimpleDelegate2 (delegate_test_struct
);
188 return mono_test_marshal_delegate2 (d
);
191 /* Test structures as byref arguments of delegates */
192 public static int test_0_marshal_byref_struct_delegate () {
193 SimpleStruct ss
= new SimpleStruct ();
194 TestDelegate d
= new TestDelegate (delegate_test_struct_byref
);
199 if (mono_test_ref_vtype (1, ref ss
, 2, d
) != 0)
202 if (! (ss
.a
&& ss
.b
&& ss
.c
&& ss
.d
== "TEST3"))
208 /* Test structures as out arguments of delegates */
209 public static int test_0_marshal_out_struct_delegate () {
210 SimpleStruct ss
= new SimpleStruct ();
211 OutStructDelegate d
= new OutStructDelegate (delegate_test_struct_out
);
213 return mono_test_marshal_out_struct (1, out ss
, 2, d
);
216 /* Test classes as arguments and return values of delegates */
217 public static int test_0_marshal_class_delegate () {
218 SimpleDelegate4 d
= new SimpleDelegate4 (delegate_test_class
);
220 return mono_test_marshal_delegate4 (d
);
223 /* Test classes as byref arguments of delegates */
224 public static int test_0_marshal_byref_class_delegate () {
225 SimpleDelegate5 d
= new SimpleDelegate5 (delegate_test_class_byref
);
227 return mono_test_marshal_delegate5 (d
);
230 /* Test classes as out arguments of delegates */
231 public static int test_0_marshal_out_class_delegate () {
232 SimpleDelegate7 d
= new SimpleDelegate7 (delegate_test_class_out
);
234 return mono_test_marshal_delegate7 (d
);
237 /* Test string marshalling with delegates */
238 public static int test_0_marshal_string_delegate () {
239 SimpleDelegate8 d
= new SimpleDelegate8 (delegate_test_string_marshalling
);
241 return mono_test_marshal_delegate8 (d
, "ABC");
244 /* Test that the delegate wrapper correctly catches null byref arguments */
245 public static int test_0_marshal_byref_class_delegate_null () {
246 SimpleDelegate5 d
= new SimpleDelegate5 (delegate_test_class_byref
);
249 mono_test_marshal_delegate6 (d
);
252 catch (ArgumentNullException ex
) {
257 static int return_self (int i
) {
261 static int call_int_delegate (return_int_delegate d
) {
265 public static int test_55_marshal_delegate_delegate () {
266 SimpleDelegate9 d
= new SimpleDelegate9 (call_int_delegate
);
268 return mono_test_marshal_delegate9 (d
, new return_int_delegate (return_self
));
271 public static int test_0_marshal_primitive_byref_delegate () {
272 PrimitiveByrefDelegate d
= new PrimitiveByrefDelegate (delegate_test_primitive_byref
);
274 return mono_test_marshal_primitive_byref_delegate (d
);
277 public static return_int_delegate
return_delegate () {
278 return new return_int_delegate (return_self
);
281 public static int test_55_marshal_return_delegate_delegate () {
282 return mono_test_marshal_return_delegate_delegate (new ReturnDelegateDelegate (return_delegate
));
285 /* Passing and returning strings */
287 public delegate String
ReturnStringDelegate (String s
);
289 [DllImport ("libtest", EntryPoint
="mono_test_return_string")]
290 public static extern String
mono_test_marshal_return_string_delegate (ReturnStringDelegate d
);
292 public static String
managed_return_string (String s
) {
299 public static int test_0_marshal_return_string_delegate () {
300 ReturnStringDelegate d
= new ReturnStringDelegate (managed_return_string
);
301 String s
= mono_test_marshal_return_string_delegate (d
);
303 return (s
== "12345") ? 0 : 1;
306 /* Passing and returning enums */
308 public enum FooEnum
{
314 public delegate FooEnum
ReturnEnumDelegate (FooEnum e
);
316 [DllImport ("libtest", EntryPoint
="mono_test_marshal_return_enum_delegate")]
317 public static extern int mono_test_marshal_return_enum_delegate (ReturnEnumDelegate d
);
319 public static FooEnum
managed_return_enum (FooEnum e
) {
320 return (FooEnum
)((int)e
+ 1);
323 public static int test_0_marshal_return_enum_delegate () {
324 ReturnEnumDelegate d
= new ReturnEnumDelegate (managed_return_enum
);
325 FooEnum e
= (FooEnum
)mono_test_marshal_return_enum_delegate (d
);
327 return e
== FooEnum
.Foo3
? 0 : 1;
330 /* Passing and returning blittable structs */
332 [StructLayout (LayoutKind
.Sequential
)]
333 public struct BlittableStruct
{
338 public static BlittableStruct
delegate_test_blittable_struct (BlittableStruct ss
)
350 public delegate BlittableStruct
SimpleDelegate10 (BlittableStruct ss
);
352 [DllImport ("libtest", EntryPoint
="mono_test_marshal_blittable_struct_delegate")]
353 public static extern int mono_test_marshal_blittable_struct_delegate (SimpleDelegate10 d
);
355 public static int test_0_marshal_blittable_struct_delegate () {
356 return mono_test_marshal_blittable_struct_delegate (new SimpleDelegate10 (delegate_test_blittable_struct
));
360 * Passing and returning small structs
363 /* TEST 1: 4 byte long INTEGER struct */
365 [StructLayout (LayoutKind
.Sequential
)]
366 public struct SmallStruct1
{
370 public static SmallStruct1
delegate_test_struct (SmallStruct1 ss
) {
378 public delegate SmallStruct1
SmallStructDelegate1 (SmallStruct1 ss
);
380 [DllImport ("libtest", EntryPoint
="mono_test_marshal_small_struct_delegate1")]
381 public static extern int mono_test_marshal_small_struct_delegate (SmallStructDelegate1 d
);
383 public static int test_0_marshal_small_struct_delegate1 () {
384 return mono_test_marshal_small_struct_delegate (new SmallStructDelegate1 (delegate_test_struct
));
387 /* TEST 2: 2+2 byte long INTEGER struct */
389 [StructLayout (LayoutKind
.Sequential
)]
390 public struct SmallStruct2
{
394 public static SmallStruct2
delegate_test_struct (SmallStruct2 ss
) {
397 res
.i
= (short)-ss
.i
;
398 res
.j
= (short)-ss
.j
;
403 public delegate SmallStruct2
SmallStructDelegate2 (SmallStruct2 ss
);
405 [DllImport ("libtest", EntryPoint
="mono_test_marshal_small_struct_delegate2")]
406 public static extern int mono_test_marshal_small_struct_delegate (SmallStructDelegate2 d
);
408 public static int test_0_marshal_small_struct_delegate2 () {
409 return mono_test_marshal_small_struct_delegate (new SmallStructDelegate2 (delegate_test_struct
));
412 /* TEST 3: 2+1 byte long INTEGER struct */
414 [StructLayout (LayoutKind
.Sequential
)]
415 public struct SmallStruct3
{
420 public static SmallStruct3
delegate_test_struct (SmallStruct3 ss
) {
423 res
.i
= (short)-ss
.i
;
429 public delegate SmallStruct3
SmallStructDelegate3 (SmallStruct3 ss
);
431 [DllImport ("libtest", EntryPoint
="mono_test_marshal_small_struct_delegate3")]
432 public static extern int mono_test_marshal_small_struct_delegate (SmallStructDelegate3 d
);
434 public static int test_0_marshal_small_struct_delegate3 () {
435 return mono_test_marshal_small_struct_delegate (new SmallStructDelegate3 (delegate_test_struct
));
438 /* TEST 4: 2 byte long INTEGER struct */
440 [StructLayout (LayoutKind
.Sequential
)]
441 public struct SmallStruct4
{
445 public static SmallStruct4
delegate_test_struct (SmallStruct4 ss
) {
448 res
.i
= (short)-ss
.i
;
453 public delegate SmallStruct4
SmallStructDelegate4 (SmallStruct4 ss
);
455 [DllImport ("libtest", EntryPoint
="mono_test_marshal_small_struct_delegate4")]
456 public static extern int mono_test_marshal_small_struct_delegate (SmallStructDelegate4 d
);
458 public static int test_0_marshal_small_struct_delegate4 () {
459 return mono_test_marshal_small_struct_delegate (new SmallStructDelegate4 (delegate_test_struct
));
462 /* TEST 5: 8 byte long INTEGER struct */
464 [StructLayout (LayoutKind
.Sequential
)]
465 public struct SmallStruct5
{
469 public static SmallStruct5
delegate_test_struct (SmallStruct5 ss
) {
477 public delegate SmallStruct5
SmallStructDelegate5 (SmallStruct5 ss
);
479 [DllImport ("libtest", EntryPoint
="mono_test_marshal_small_struct_delegate5")]
480 public static extern int mono_test_marshal_small_struct_delegate (SmallStructDelegate5 d
);
482 public static int test_0_marshal_small_struct_delegate5 () {
483 return mono_test_marshal_small_struct_delegate (new SmallStructDelegate5 (delegate_test_struct
));
486 /* TEST 6: 4+4 byte long INTEGER struct */
488 [StructLayout (LayoutKind
.Sequential
)]
489 public struct SmallStruct6
{
493 public static SmallStruct6
delegate_test_struct (SmallStruct6 ss
) {
502 public delegate SmallStruct6
SmallStructDelegate6 (SmallStruct6 ss
);
504 [DllImport ("libtest", EntryPoint
="mono_test_marshal_small_struct_delegate6")]
505 public static extern int mono_test_marshal_small_struct_delegate (SmallStructDelegate6 d
);
507 public static int test_0_marshal_small_struct_delegate6 () {
508 return mono_test_marshal_small_struct_delegate (new SmallStructDelegate6 (delegate_test_struct
));
511 /* TEST 7: 4+2 byte long INTEGER struct */
513 [StructLayout (LayoutKind
.Sequential
)]
514 public struct SmallStruct7
{
519 public static SmallStruct7
delegate_test_struct (SmallStruct7 ss
) {
523 res
.j
= (short)-ss
.j
;
528 public delegate SmallStruct7
SmallStructDelegate7 (SmallStruct7 ss
);
530 [DllImport ("libtest", EntryPoint
="mono_test_marshal_small_struct_delegate7")]
531 public static extern int mono_test_marshal_small_struct_delegate (SmallStructDelegate7 d
);
533 public static int test_0_marshal_small_struct_delegate7 () {
534 return mono_test_marshal_small_struct_delegate (new SmallStructDelegate7 (delegate_test_struct
));
537 /* TEST 8: 4 byte long FLOAT struct */
539 [StructLayout (LayoutKind
.Sequential
)]
540 public struct SmallStruct8
{
544 public static SmallStruct8
delegate_test_struct (SmallStruct8 ss
) {
552 public delegate SmallStruct8
SmallStructDelegate8 (SmallStruct8 ss
);
554 [DllImport ("libtest", EntryPoint
="mono_test_marshal_small_struct_delegate8")]
555 public static extern int mono_test_marshal_small_struct_delegate (SmallStructDelegate8 d
);
557 public static int test_0_marshal_small_struct_delegate8 () {
558 return mono_test_marshal_small_struct_delegate (new SmallStructDelegate8 (delegate_test_struct
));
561 /* TEST 9: 8 byte long FLOAT struct */
563 [StructLayout (LayoutKind
.Sequential
)]
564 public struct SmallStruct9
{
568 public static SmallStruct9
delegate_test_struct (SmallStruct9 ss
) {
576 public delegate SmallStruct9
SmallStructDelegate9 (SmallStruct9 ss
);
578 [DllImport ("libtest", EntryPoint
="mono_test_marshal_small_struct_delegate9")]
579 public static extern int mono_test_marshal_small_struct_delegate (SmallStructDelegate9 d
);
581 public static int test_0_marshal_small_struct_delegate9 () {
582 return mono_test_marshal_small_struct_delegate (new SmallStructDelegate9 (delegate_test_struct
));
585 /* TEST 10: 4+4 byte long FLOAT struct */
587 [StructLayout (LayoutKind
.Sequential
)]
588 public struct SmallStruct10
{
593 public static SmallStruct10
delegate_test_struct (SmallStruct10 ss
) {
602 public delegate SmallStruct10
SmallStructDelegate10 (SmallStruct10 ss
);
604 [DllImport ("libtest", EntryPoint
="mono_test_marshal_small_struct_delegate10")]
605 public static extern int mono_test_marshal_small_struct_delegate (SmallStructDelegate10 d
);
607 public static int test_0_marshal_small_struct_delegate10 () {
608 return mono_test_marshal_small_struct_delegate (new SmallStructDelegate10 (delegate_test_struct
));
611 /* TEST 11: 4+4 byte long MIXED struct */
613 [StructLayout (LayoutKind
.Sequential
)]
614 public struct SmallStruct11
{
619 public static SmallStruct11
delegate_test_struct (SmallStruct11 ss
) {
628 public delegate SmallStruct11
SmallStructDelegate11 (SmallStruct11 ss
);
630 [DllImport ("libtest", EntryPoint
="mono_test_marshal_small_struct_delegate11")]
631 public static extern int mono_test_marshal_small_struct_delegate (SmallStructDelegate11 d
);
633 public static int test_0_marshal_small_struct_delegate11 () {
634 return mono_test_marshal_small_struct_delegate (new SmallStructDelegate11 (delegate_test_struct
));
640 public delegate int ArrayDelegate1 (int i
,
642 [In
, MarshalAs(UnmanagedType
.LPArray
,
643 ArraySubType
=UnmanagedType
.LPStr
, SizeParamIndex
=0)] string[] arr
);
645 [DllImport ("libtest", EntryPoint
="mono_test_marshal_array_delegate")]
646 public static extern int mono_test_marshal_array_delegate1 (string[] arr
, int len
, ArrayDelegate1 d
);
648 public static int array_delegate1 (int i
, string j
, string[] arr
) {
651 if ((arr
[0] != "ABC") || (arr
[1] != "DEF"))
656 public static int test_0_marshal_array_delegate_string () {
657 string[] arr
= new string [] { "ABC", "DEF" }
;
658 return mono_test_marshal_array_delegate1 (arr
, arr
.Length
, new ArrayDelegate1 (array_delegate1
));
661 public static int array_delegate2 (int i
, string j
, string[] arr
) {
662 return (arr
== null) ? 0 : 1;
665 public static int test_0_marshal_array_delegate_null () {
666 return mono_test_marshal_array_delegate1 (null, 0, new ArrayDelegate1 (array_delegate2
));
669 public delegate int ArrayDelegate3 (int i
,
671 [In
, MarshalAs(UnmanagedType
.LPArray
,
672 ArraySubType
=UnmanagedType
.LPStr
, SizeParamIndex
=3)] string[] arr
);
674 [DllImport ("libtest", EntryPoint
="mono_test_marshal_array_delegate")]
675 public static extern int mono_test_marshal_array_delegate3 (string[] arr
, int len
, ArrayDelegate3 d
);
677 public static int array_delegate3 (int i
, string j
, string[] arr
) {
678 return (arr
== null) ? 0 : 1;
681 public static int test_0_marshal_array_delegate_bad_paramindex () {
683 mono_test_marshal_array_delegate3 (null, 0, new ArrayDelegate3 (array_delegate3
));
686 catch (MarshalDirectiveException
) {
691 public delegate int ArrayDelegate4 (int i
,
693 [In
, MarshalAs(UnmanagedType
.LPArray
,
694 ArraySubType
=UnmanagedType
.LPStr
, SizeParamIndex
=1)] string[] arr
);
696 [DllImport ("libtest", EntryPoint
="mono_test_marshal_array_delegate")]
697 public static extern int mono_test_marshal_array_delegate4 (string[] arr
, int len
, ArrayDelegate4 d
);
699 public static int array_delegate4 (int i
, string j
, string[] arr
) {
700 return (arr
== null) ? 0 : 1;
703 public static int test_0_marshal_array_delegate_bad_paramtype () {
705 mono_test_marshal_array_delegate4 (null, 0, new ArrayDelegate4 (array_delegate4
));
708 catch (MarshalDirectiveException
) {
713 public delegate int ArrayDelegate5 (int i
,
715 [In
, MarshalAs(UnmanagedType
.LPArray
,
716 ArraySubType
=UnmanagedType
.LPWStr
, SizeParamIndex
=0)] string[] arr
);
718 [DllImport ("libtest", EntryPoint
="mono_test_marshal_array_delegate", CharSet
=CharSet
.Unicode
)]
719 public static extern int mono_test_marshal_array_delegate5 (string[] arr
, int len
, ArrayDelegate5 d
);
721 public static int array_delegate5 (int i
, string j
, string[] arr
) {
724 if ((arr
[0] != "ABC") || (arr
[1] != "DEF"))
729 public static int test_0_marshal_array_delegate_unicode_string () {
730 string[] arr
= new string [] { "ABC", "DEF" }
;
731 return mono_test_marshal_array_delegate5 (arr
, arr
.Length
, new ArrayDelegate5 (array_delegate5
));
734 public delegate int ArrayDelegate6 (int i
,
736 [In
, MarshalAs(UnmanagedType
.LPArray
,
737 ArraySubType
=UnmanagedType
.LPStr
, SizeConst
=2)] string[] arr
);
739 [DllImport ("libtest", EntryPoint
="mono_test_marshal_array_delegate")]
740 public static extern int mono_test_marshal_array_delegate6 (string[] arr
, int len
, ArrayDelegate6 d
);
742 public static int array_delegate6 (int i
, string j
, string[] arr
) {
745 if ((arr
[0] != "ABC") || (arr
[1] != "DEF"))
750 public static int test_0_marshal_array_delegate_sizeconst () {
751 string[] arr
= new string [] { "ABC", "DEF" }
;
752 return mono_test_marshal_array_delegate6 (arr
, 1024, new ArrayDelegate6 (array_delegate6
));
755 public delegate int ArrayDelegate7 (int i
,
757 [In
, MarshalAs(UnmanagedType
.LPArray
,
758 ArraySubType
=UnmanagedType
.LPStr
, SizeConst
=1, SizeParamIndex
=0)] string[] arr
);
760 [DllImport ("libtest", EntryPoint
="mono_test_marshal_array_delegate")]
761 public static extern int mono_test_marshal_array_delegate7 (string[] arr
, int len
, ArrayDelegate7 d
);
763 public static int array_delegate7 (int i
, string j
, string[] arr
) {
766 if ((arr
[0] != "ABC") || (arr
[1] != "DEF"))
771 public static int test_0_marshal_array_delegate_sizeconst_paramindex () {
772 string[] arr
= new string [] { "ABC", "DEF" }
;
773 return mono_test_marshal_array_delegate7 (arr
, 1, new ArrayDelegate7 (array_delegate7
));
776 public delegate int ArrayDelegate8 (int i
, string j
,
777 [In
, MarshalAs(UnmanagedType
.LPArray
,
781 [DllImport ("libtest", EntryPoint
="mono_test_marshal_array_delegate")]
782 public static extern int mono_test_marshal_array_delegate8 (int[] arr
, int len
, ArrayDelegate8 d
);
784 public static int array_delegate8 (int i
, string j
, int[] arr
) {
787 if ((arr
[0] != 42) || (arr
[1] != 43))
792 public static int test_0_marshal_array_delegate_blittable () {
793 int[] arr
= new int [] { 42, 43 }
;
794 return mono_test_marshal_array_delegate8 (arr
, 2, new ArrayDelegate8 (array_delegate8
));
798 * [Out] blittable arrays
801 public delegate int ArrayDelegate9 (int i
, string j
,
802 [Out
, MarshalAs(UnmanagedType
.LPArray
,
806 [DllImport ("libtest", EntryPoint
="mono_test_marshal_out_array_delegate")]
807 public static extern int mono_test_marshal_out_array_delegate (int[] arr
, int len
, ArrayDelegate9 d
);
809 public static int array_delegate9 (int i
, string j
, int[] arr
) {
819 public static int test_0_marshal_out_array_delegate () {
820 int[] arr
= new int [] { 42, 43 }
;
821 return mono_test_marshal_out_array_delegate (arr
, 2, new ArrayDelegate9 (array_delegate9
));
825 * [Out] string arrays
828 public delegate int ArrayDelegate10 (int i
,
830 [Out
, MarshalAs(UnmanagedType
.LPArray
,
831 ArraySubType
=UnmanagedType
.LPStr
, SizeConst
=2)] string[] arr
);
833 [DllImport ("libtest", EntryPoint
="mono_test_marshal_out_string_array_delegate")]
834 public static extern int mono_test_marshal_out_string_array_delegate (string[] arr
, int len
, ArrayDelegate10 d
);
836 public static int array_delegate10 (int i
, string j
, string[] arr
) {
846 public static int test_0_marshal_out_string_array_delegate () {
847 string[] arr
= new string [] { "", "" }
;
848 return mono_test_marshal_out_string_array_delegate (arr
, 2, new ArrayDelegate10 (array_delegate10
));
855 public delegate int InOutByvalClassDelegate ([In
, Out
] SimpleClass ss
);
857 [DllImport ("libtest", EntryPoint
="mono_test_marshal_inout_byval_class_delegate")]
858 public static extern int mono_test_marshal_inout_byval_class_delegate (InOutByvalClassDelegate d
);
860 public static int delegate_test_byval_class_inout (SimpleClass ss
) {
861 if ((ss
.a
!= false) || (ss
.b
!= true) || (ss
.c
!= false) || (ss
.d
!= "FOO"))
872 public static int test_0_marshal_inout_byval_class_delegate () {
873 return mono_test_marshal_inout_byval_class_delegate (new InOutByvalClassDelegate (delegate_test_byval_class_inout
));
877 * Returning unicode strings
879 [return: MarshalAs(UnmanagedType
.LPWStr
)]
880 public delegate string ReturnUnicodeStringDelegate([MarshalAs(UnmanagedType
.LPWStr
)] string message
);
882 [DllImport ("libtest", EntryPoint
="mono_test_marshal_return_unicode_string_delegate")]
883 public static extern int mono_test_marshal_return_unicode_string_delegate (ReturnUnicodeStringDelegate d
);
885 public static String
return_unicode_string_delegate (string message
) {
889 public static int test_0_marshal_return_unicode_string_delegate () {
890 return mono_test_marshal_return_unicode_string_delegate (new ReturnUnicodeStringDelegate (return_unicode_string_delegate
));
894 * Returning string arrays
896 public delegate string[] ReturnArrayDelegate (int i
);
898 [DllImport ("libtest", EntryPoint
="mono_test_marshal_return_string_array_delegate")]
899 public static extern int mono_test_marshal_return_string_array_delegate (ReturnArrayDelegate d
);
901 public static String
[] return_array_delegate (int i
) {
902 String
[] arr
= new String
[2];
910 public static String
[] return_array_delegate_null (int i
) {
914 public static int test_0_marshal_return_string_array_delegate () {
915 return mono_test_marshal_return_string_array_delegate (new ReturnArrayDelegate (return_array_delegate
));
918 public static int test_3_marshal_return_string_array_delegate_null () {
919 return mono_test_marshal_return_string_array_delegate (new ReturnArrayDelegate (return_array_delegate_null
));