码迷,mamicode.com
首页 > Windows程序 > 详细

c# 调用User32.dll

时间:2019-07-24 00:01:46      阅读:143      评论:0      收藏:0      [点我收藏+]

标签:free   ace   code   throw   sha   static   使用方法   tsp   alt   

获取当前窗口句柄:GetForegroundWindow()
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern IntPtr GetForegroundWindow();

使用方法   IntPtr myPtr=GetForegroundWindow();
  [DllImport("kernel32.dll")]
   static extern IntPtr LoadLibrary(string lpFileName);

   [DllImport("kernel32.dll", SetLastError = true)]
   static extern bool FreeLibrary(IntPtr hModule);
// <summary>
        /// Loadlibrary 返回的函数库模块的句柄
        /// </summary>
        private IntPtr hModule = IntPtr.Zero;
     /// <summary>
        /// 装载 Dll
        /// </summary>
        /// <param name="lpFileName">DLL 文件名 </param>
        public void LoadDll(string lpFileName)
        {
            hModule = LoadLibrary(lpFileName);
            if (hModule == IntPtr.Zero)
            {
                throw (new Exception(" 没有找到 :" + lpFileName + "."));
            }
        }
        /// <summary>
        /// 卸载 Dll
        /// </summary>
        public void UnLoadDll()
        {
            FreeLibrary(hModule);
            hModule = IntPtr.Zero;
        }
    

 

c# 调用User32.dll

标签:free   ace   code   throw   sha   static   使用方法   tsp   alt   

原文地址:https://www.cnblogs.com/zutian/p/11235029.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!