我知道你会因为这种问题而恨我。但是有人可以告诉我以下代码在做什么吗?
我的意思是加载了一些库,我明白了。还有一些方法,我还是不明白。
例如:
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
代码如下:
private static class API
{
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern IntPtr SetWindowsHookEx(
int idHook,
HookDel lpfn,
IntPtr hMod,
uint dwThreadId);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool UnhookWindowsHookEx(IntPtr hhk);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern IntPtr CallNextHookEx(
IntPtr hhk,
int nCode,
IntPtr wParam,
IntPtr lParam);
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern IntPtr GetModuleHandle(
string lpModuleName);
}
您不必逐行向我解释。请至少给我一些可以阅读的引用。
提前致谢!
最佳答案
此代码使用 P/Invoke允许 C# 代码调用多个与 Windows Hooks 相关的 Win32 API 函数.
发布的代码只定义了方法;它不调用它们,所以它自己不做任何事情。它只允许您使用代码其他部分的方法。
关于c# - 这个 API 到底是什么,它在做什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6801717/