コード例 #1
0
ファイル: Initialize.cs プロジェクト: markdwags/UOMachine
        public static void Initialize(ClientInstance clientInstance)
        {
            myWindowHandle   = Process.GetCurrentProcess().MainWindowHandle;
            myClientInstance = clientInstance;
            myMsgHook        = new NativeMethods.HookProc(MsgHook);
            myWindowMsgHook  = new NativeMethods.HookProc(WindowMsgHook);
            Process p = Process.GetProcessById(EasyHook.RemoteHooking.GetCurrentProcessId());
            uint    x;
            uint    threadID = NativeMethods.GetWindowThreadProcessId(p.MainWindowHandle, out x);

            /* Use user32.dll as SetWindowHookEx hMod as per http://stackoverflow.com/questions/17897646/gma-useractivitymonitor-setwindowshookex-error-126 */
            IntPtr user32 = NativeMethods.LoadLibrary("user32.dll");

            myMsgHookHandle = NativeMethods.SetWindowsHookEx(NativeMethods.WH_GETMESSAGE,
                                                             Marshal.GetFunctionPointerForDelegate(myMsgHook),
                                                             /*Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly().GetModules()[0])*/ user32,
                                                             threadID);
#if DEBUG
            if (myMsgHookHandle == IntPtr.Zero)
            {
                clientInstance.SendCommand(Command.Message, "Error installing WH_GETMESSAGE hook, GetLastError = " + Marshal.GetLastWin32Error().ToString());
            }
#endif
            myWindowMsgHookHandle = NativeMethods.SetWindowsHookEx(NativeMethods.WH_CALLWNDPROC,
                                                                   Marshal.GetFunctionPointerForDelegate(myWindowMsgHook),
                                                                   /*Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly().GetModules()[0])*/ user32,
                                                                   threadID);
#if DEBUG
            if (myWindowMsgHookHandle == IntPtr.Zero)
            {
                clientInstance.SendCommand(Command.Message, "Error installing WH_CALLWNDPROC hook, GetLastError = " + Marshal.GetLastWin32Error().ToString());
            }
#endif
            NativeMethods.WINDOWPLACEMENT wp = new NativeMethods.WINDOWPLACEMENT();
            if (NativeMethods.GetWindowPlacement(myWindowHandle, ref wp))
            {
                MessageHook.myWindowX = wp.rcNormalPosition.X;
                MessageHook.myWindowY = wp.rcNormalPosition.Y;
            }
            if (myMsgHookHandle == IntPtr.Zero || myWindowMsgHookHandle == IntPtr.Zero)
            {
                clientInstance.SendCommand(Command.Message, "Error installing WH_GETMESSAGE\\WH_CALLWNDPROC hooks!");
            }
        }
コード例 #2
0
ファイル: Initialize.cs プロジェクト: nazariitashak/UOMachine
        public static void Initialize(ClientInstance clientInstance)
        {
            myWindowHandle = Process.GetCurrentProcess().MainWindowHandle;
            myClientInstance = clientInstance;
            myMsgHook = new NativeMethods.HookProc(MsgHook);
            myWindowMsgHook = new NativeMethods.HookProc(WindowMsgHook);
            Process p = Process.GetProcessById(EasyHook.RemoteHooking.GetCurrentProcessId());
            uint x;
            uint threadID = NativeMethods.GetWindowThreadProcessId(p.MainWindowHandle, out x);

            /* Use user32.dll as SetWindowHookEx hMod as per http://stackoverflow.com/questions/17897646/gma-useractivitymonitor-setwindowshookex-error-126 */
            IntPtr user32 = NativeMethods.LoadLibrary("user32.dll");
            myMsgHookHandle = NativeMethods.SetWindowsHookEx(NativeMethods.WH_GETMESSAGE,
                Marshal.GetFunctionPointerForDelegate(myMsgHook),
                /*Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly().GetModules()[0])*/user32,
                    threadID);
            #if DEBUG
            if (myMsgHookHandle == IntPtr.Zero)
            {
                clientInstance.SendCommand(Command.Message, "Error installing WH_GETMESSAGE hook, GetLastError = " + Marshal.GetLastWin32Error().ToString());
            }
            #endif
            myWindowMsgHookHandle = NativeMethods.SetWindowsHookEx(NativeMethods.WH_CALLWNDPROC,
                Marshal.GetFunctionPointerForDelegate(myWindowMsgHook),
                /*Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly().GetModules()[0])*/user32,
                    threadID);
            #if DEBUG
            if (myWindowMsgHookHandle == IntPtr.Zero)
            {
                clientInstance.SendCommand(Command.Message, "Error installing WH_CALLWNDPROC hook, GetLastError = " + Marshal.GetLastWin32Error().ToString());
            }
            #endif
            NativeMethods.WINDOWPLACEMENT wp = new NativeMethods.WINDOWPLACEMENT();
            if (NativeMethods.GetWindowPlacement(myWindowHandle, ref wp))
            {
                MessageHook.myWindowX = wp.rcNormalPosition.X;
                MessageHook.myWindowY = wp.rcNormalPosition.Y;
            }
            if (myMsgHookHandle == IntPtr.Zero || myWindowMsgHookHandle == IntPtr.Zero)
            {
                clientInstance.SendCommand(Command.Message, "Error installing WH_GETMESSAGE\\WH_CALLWNDPROC hooks!");
            }
        }