// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Diagnostics; using System.Runtime.InteropServices; namespace E { public class Program { [DllImport(@"C:\Job.dll")] private static extern IntPtr setup(int mem); [DllImport(@"C:\Job.dll")] private static extern void teardown(IntPtr job); public static void Main(string[] args) { IntPtr job = IntPtr.Zero; try { job = setup(10000000); //byte[] b = new byte[10000000]; byte[] b = new byte[1000000]; Console.WriteLine("ok"); } catch(OutOfMemoryException) { Console.WriteLine("oops"); } finally { if(job != IntPtr.Zero) teardown(job); } } } }