2005-04-12 Dick Porter <dick@ximian.com>
[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                 bool win = ((int) Environment.OSVersion.Platform != 128);
18                 Console.WriteLine ("Running on {0}...", Environment.OSVersion);
19                 return win;
20         }
21
22         static int Test ()
23         {
24                 try {
25                         uint u = (RunningOnWindows () ? GetTickCount () : getuid ());
26                         Console.WriteLine ("*0* P/Invoke: {0}", u);
27                         return 0;
28                 }
29                 catch (SecurityException se) {
30                         Console.WriteLine ("*1* Unexpected SecurityException\n{0}", se);
31                         return 1;
32                 }
33                 catch (Exception e) {
34                         Console.WriteLine ("*2* Unexpected exception\n{0}", e);
35                         return 2;
36                 }
37         }
38
39         static int Main ()
40         {
41                 return Test ();
42         }
43 }