merging the Mainsoft branch to the trunk
[mono.git] / mono / tests / cas / demand / pinvoke1.cs
1 using System;
2 using System.Runtime.InteropServices;
3 using System.Security;
4
5 public class Program {
6
7         // for Mono
8         [DllImport ("libc", SetLastError=true)]
9         public static extern uint getuid ();
10
11         // for Microsoft
12         [DllImport ("kernel32.dll", SetLastError=true)]
13         public static extern uint GetTickCount ();
14
15         static bool RunningOnWindows ()
16         {
17                 int p = (int) Environment.OSVersion.Platform;
18                 bool win = ((p != 4) && (p != 128));
19                 Console.WriteLine ("Running on {0}...", Environment.OSVersion);
20                 return win;
21         }
22
23         static int Test ()
24         {
25                 try {
26                         uint u = (RunningOnWindows () ? GetTickCount () : getuid ());
27                         Console.WriteLine ("*0* P/Invoke: {0}", u);
28                         return 0;
29                 }
30                 catch (SecurityException se) {
31                         Console.WriteLine ("*1* Unexpected SecurityException\n{0}", se);
32                         return 1;
33                 }
34                 catch (Exception e) {
35                         Console.WriteLine ("*2* Unexpected exception\n{0}", e);
36                         return 2;
37                 }
38         }
39
40         static int Main ()
41         {
42                 return Test ();
43         }
44 }