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);
}
}
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);
}
}