c# 调用User32.dll
Posted zutian
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c# 调用User32.dll相关的知识,希望对你有一定的参考价值。
获取当前窗口句柄: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;
/// 卸载 Dll
/// </summary>
public void UnLoadDll()
FreeLibrary(hModule);
hModule = IntPtr.Zero;
以上是关于c# 调用User32.dll的主要内容,如果未能解决你的问题,请参考以下文章
C#中调用user32.dll库的keybd_Event函数,操作键盘
如何从 javascript 调用 user32.dll 方法