2003-10-13 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mono / tests / pinvoke6.cs
1 using System;
2 using System.Runtime.InteropServices;
3
4 public class Test {
5
6         [StructLayout (LayoutKind.Sequential)]
7         public struct SimpleStruct {
8                 public bool a;
9                 public bool b;
10                 public bool c;
11                 public string d;
12         }
13
14         [DllImport ("libtest", EntryPoint="mono_test_ref_vtype")]
15         public static extern int mono_test_ref_vtype (int a, ref SimpleStruct ss, int b, TestDelegate d);
16
17         public static int managed_test_ref_vtype (int a, ref SimpleStruct ss, int b)
18         {
19                 Console.WriteLine ("Delegate called");
20                 
21                 if (a == 1 && b == 2 && ss.a && !ss.b && ss.c && ss.d == "TEST2")
22                         return 0;
23
24                 return 1;
25         }
26
27         public delegate int TestDelegate (int a, ref SimpleStruct ss, int b);
28
29
30         public static int Main () {
31                 SimpleStruct ss = new SimpleStruct ();
32                 TestDelegate d = new TestDelegate (managed_test_ref_vtype);
33                 
34                 ss.b = true;
35                 ss.d = "TEST1";
36
37                 if (mono_test_ref_vtype (1, ref ss, 2, d) != 0)
38                         return 1;
39                 
40                 if (ss.a && !ss.b && ss.c && ss.d == "TEST2")
41                         return 0;
42                 
43                 return 1;
44         }
45 }