2007-12-06 Jb Evain <jbevain@novell.com>
[mono.git] / mono / tests / pinvoke17.cs
blob9572fffe1f05cbd413c3dc1b1e1a2f3b73396c00
1 using System;
2 using System.Runtime.InteropServices;
4 [StructLayout (LayoutKind.Sequential)]
5 public class OSVersionInfo
6 {
7 public int a;
8 public int b;
11 [StructLayout (LayoutKind.Sequential)]
12 public struct OSVersionInfo2
14 public int a;
15 public int b;
19 public class LibWrap
21 [DllImport ("libtest", EntryPoint="MyGetVersionEx")]
22 public static extern int GetVersionEx ([In, Out] OSVersionInfo osvi);
24 [DllImport ("libtest")]
25 public static extern int BugGetVersionEx (int a, int b, int c, int d, int e, int f, int g, int h, [In, Out] OSVersionInfo osvi);
27 [DllImport ("libtest", EntryPoint="MyGetVersionEx")]
28 public static extern int GetVersionEx2 (ref OSVersionInfo2 osvi);
31 public class Test
33 public static int Main()
35 Console.WriteLine( "\nPassing OSVersionInfo as class" );
37 OSVersionInfo osvi = new OSVersionInfo();
38 osvi.a = 1;
39 osvi.b = 2;
41 if (LibWrap.GetVersionEx (osvi) != 5)
42 return 1;
44 if (osvi.a != 2)
45 return 2;
47 if (osvi.b != 3)
48 return 3;
50 Console.WriteLine( "A: {0}", osvi.a);
51 Console.WriteLine( "B: {0}", osvi.b);
53 Console.WriteLine( "\nPassing OSVersionInfo as struct" );
55 OSVersionInfo2 osvi2 = new OSVersionInfo2();
56 osvi2.a = 1;
57 osvi2.b = 2;
59 if (LibWrap.GetVersionEx2 (ref osvi2) != 5)
60 return 4;
62 if (osvi2.a != 2)
63 return 5;
65 if (osvi2.b != 3)
66 return 6;
68 Console.WriteLine( "A: {0}", osvi2.a);
69 Console.WriteLine( "B: {0}", osvi2.b);
71 Console.WriteLine ("Testing with extra parameters at the beginning");
73 OSVersionInfo osvi3 = new OSVersionInfo();
74 osvi3.a = 1;
75 osvi3.b = 2;
77 if (LibWrap.BugGetVersionEx (10, 10, 10, 10, 20, 20, 20, 20, osvi3) != 5)
78 return 7;
80 if (osvi3.a != 2)
81 return 8;
83 if (osvi3.b != 3)
84 return 9;
86 Console.WriteLine( "A: {0}", osvi.a);
87 Console.WriteLine( "B: {0}", osvi.b);
89 Console.WriteLine( "\nPassing OSVersionInfo as struct" );
91 return 0;