我正试图在Windows操作系统上挂钩CBT钩子.我目前正在使用Windows 7 x64.
我已经阅读了许多关于这个问题的线索,但没有一个解决了我的问题.应用程序运行良好; 挂钩已安装,我可以看到一些通知即将到来.
实际上出现的问题是应用程序没有得到关于在同一台机器上运行的其他进程的CBT钩子的通知.
该应用程序是用C#编写的(使用Microsoft .NET).这是一个正在运行的示例:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Text;
using System.Threading;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace WindowsHook
{
class Program
{
[STAThread]
static void Main(string[] args)
{
uint thid = (uint)AppDomain.GetCurrentThreadId();
bool global = true;
mHookDelegate = Marshal.GetFunctionPointerForDelegate(new HookProc(ManagedCallback));
if (global == true) {
mNativeWrapperInstance = LoadLibrary("Native_x64.dll");
thid = 0;
} else {
using (Process curProcess = Process.GetCurrentProcess())
using (ProcessModule curModule = curProcess.MainModule)
{
mNativeWrapperInstance = GetModuleHandle(curModule.ModuleName);
}
} …Run Code Online (Sandbox Code Playgroud)