2005-04-12 Dick Porter <dick@ximian.com>
[mono.git] / mono / tests / cas / linkdemand / pinvoke2.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 RunningOnMono ()
16         {
17                 bool mono = (Type.GetType ("Mono.Math.BigInteger") != null); 
18                 Console.WriteLine ("Running on {0} runtime...", mono ? "Mono" : "Microsoft");
19                 return mono;
20         }
21
22         // this attribute has NO effect on LinkDemand!
23         [SuppressUnmanagedCodeSecurity]
24         static int Test ()
25         {
26                 try {
27                         uint u = (RunningOnMono ()) ? getuid () : GetTickCount ();
28                         Console.WriteLine ("*0* P/Invoke: {0}", u);
29                         return 0;
30                 }
31                 catch (SecurityException se) {
32                         Console.WriteLine ("*1* Unexpected SecurityException\n{0}", se);
33                         return 1;
34                 }
35                 catch (Exception e) {
36                         Console.WriteLine ("*2* Unexpected exception\n{0}", e);
37                         return 2;
38                 }
39         }
40
41         static int Main ()
42         {
43                 return Test ();
44         }
45 }