当你写久了应用层代码,是不是需要来玩一下硬件呀?
这个时候你就会接触到一些美妙的dll,比如user32.dll
,kernal32.dll
当然这些是非托管的代码,我们在.net中无法直接使用,所以我们会需要使用PInvoke进行调用
于是你会使用DllImport
特性标记一个方法,引入非托管函数
比如 我们希望弹出一个消息框,就会使用下面这个函数,添加DllImport
特性,表明从哪个dll引入方法
public class Win32
{
[DllImport("user32.dll")]
public static extern IntPtr MessageBox(int hWnd, String text, String caption, uint type);
}
class Program
{
static void Main(string[] args)
{
Win32.MessageBox(0,