All pastes #1612488 Raw Edit

寄せ集め

public text v1 · immutable
#1612488 ·published 2009-10-11 14:12 UTC
rendered paste body
        using System.Runtime.InteropServices;
        [UnmanagedFunctionPointer(CallingConvention.Winapi,CharSet = CharSet.Ansi)]
        private delegate int ASMAddIntDelegate(int a,int b);
        private void button1_Click(object sender, EventArgs e)
        {
            byte[] asmcode = new byte[] {0x8B, 0x44, 0x24, 0x08, 0x8B, 0x4C, 0x24, 0x04, 0x03, 0xC1, 0xC2, 0x08, 0x00};
            GCHandle gch = GCHandle.Alloc(asmcode, GCHandleType.Pinned);
            ASMAddIntDelegate asm = (ASMAddIntDelegate)Marshal.GetDelegateForFunctionPointer(gch.AddrOfPinnedObject(), typeof(ASMAddIntDelegate));
            MessageBox.Show("1 + 1 = " + asm(1, 1), "結果");
            gch.Free();
        }