How to hook an application?

后端 未结 5 1167
情书的邮戳
情书的邮戳 2020-12-18 16:20

I\'m trying to hook the creation of a windows in my C# app.

static IntPtr hhook = IntPtr.Zero;
static NativeMethods.HookProc hhookProc;

static void Main(str         


        
5条回答
  •  春和景丽
    2020-12-18 16:57

    I'm not familiar with the NativeMethod class you are referencing, but I'll make some assumptions and try to make some ground. My guess this has to do with what handle you are hooking. The

    dummy.MainWindowHandle

    represents the front most window's handle, which is usually what you are looking for. However, in this case, you are opening a MessageBox.Show() which likely has a different handle than the one you have hooked to.

    I'd assume that

    IntPtr hwndMod = NativeMethods.GetModuleHandle(Process.GetCurrentProcess().MainModule.ModuleName);
    

    is probably going to return the same result as

    dummy.Refresh();
    IntPtr hwndMod = dummy.MainWindowHandle;
    

    So I think it's safe to say that they might be giving you the handle you aren't looking for.

    Perhaps try to make a test WinForm application. That way you can grab the proper handle. Just make sure to use

    dummy.WaitForInputIdle();
    dummy.Refresh(); 
    

    before grabbing the handle to make sure you are grabbing the right handle at launch time.

提交回复
热议问题