许明会的计算机技术主页

Language:C,C++,.NET Framework(C#)
Thinking:Design Pattern,Algorithm,WPF,Windows Internals
Database:SQLServer,Oracle,MySQL,PostSQL
IT:MCITP,Exchange,Lync,Virtualization,CCNP

导航

p/invoke示例

using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;

public class MyClass
{
    [DllImport("user32.dll", EntryPoint="MessageBoxW")]
    public static extern int MessageBoxW(
        [In] System.IntPtr hWnd,
        [In] [MarshalAs(UnmanagedType.LPWStr)] string lpText,
        [In] [MarshalAs(UnmanagedType.LPWStr)] string lpCaption,
        uint uType
    );
    
    public static void Main()
    {
        MessageBox.Show("I'm from System.Windows.Forms.MessageBox ","MessageBox from CLR",
            MessageBoxButtons.OK,MessageBoxIcon.Information);
        System.Diagnostics.Process.Start("notepad");
        MessageBoxW(IntPtr.Zero,"This Application invoked MessageBoxW.","p/invoke demo",0x40);
    }
}

posted on 2013-04-25 11:26  许明会  阅读(203)  评论(0编辑  收藏  举报