DllImport调用系统DLL的方法

来源:互联网 发布:ipv6商业应用网络 编辑:程序博客网 时间:2024/04/30 15:28
        [DllImport("user32.dll", EntryPoint = "GetDoubleClickTime")]        public extern static int GetDoubleClickTime();        [DllImport("user32.dll", EntryPoint = "GetCaretBlinkTime")]        public extern static int GetCaretBlinkTime();             private void Form1_Load(object sender, EventArgs e)        {            label3.Text = GetDoubleClickTime() + "毫秒";            label4.Text = GetCaretBlinkTime() + "毫秒";        }


首先使用系统的DLL需要命名空间。这里使用的是:

using System.Runtime.InteropServices;


[DllImport("user32.dll", EntryPoint = "GetDoubleClickTime")]        public extern static int GetDoubleClickTime();

以上为一对,如果再调用其他的,也是这个格式。

成对出现即可。


这个小程序的作用是调用系统的user32.dll里的函数,得到鼠标双击的时间间隔与光标闪烁的时间。

以上为 C# 1200例中的例子。


运行的效果:


0 0
原创粉丝点击