// 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.Runtime.InteropServices; namespace E { public class Program { [StructLayout(LayoutKind.Sequential)] struct foo { public int a; public int b; } [DllImport(@"C:\foobar.dll")] static extern void bar1(ref foo f); [DllImport(@"C:\foobar.dll")] static extern void bar2(ref foo f, int v); public static void Main(string[] args) { foo f; f.a = 11; f.b = 21; Console.WriteLine("values before bar1: " + f.a + " " + f.b); bar1(ref f); Console.WriteLine("values after bar1: " + f.a + " " + f.b); Console.WriteLine("values before bar2: " + f.a + " " + f.b); bar2(ref f, 1); Console.WriteLine("values after bar2: " + f.a + " " + f.b); } } }