Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6894311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:46:00+00:00 2026-05-27T06:46:00+00:00

How can i hook the foreground window? Currently I’m trying with using (Process processTmp

  • 0

How can i hook the foreground window?

Currently I’m trying with

using (Process processTmp = Process.GetCurrentProcess())
{
  using (ProcessModule module = processTmp.MainModule)
  {
    IntPtr hModule = Win32.GetModuleHandle(module.ModuleName);
    uint threadid = Win32.GetWindowThreadProcessId(Win32.GetForegroundWindow(), IntPtr.Zero);

    //WH_CALLWNDPROC = 4
    m_HookId = Win32.SetWindowsHookEx(4, m_HookProcedure, hModule, threadid); 
    if (m_HookId == IntPtr.Zero)
    {
      int tmp =
        Marshal.GetLastWin32Error();
    }
  }
}

But m_HookID is always IntPtr.Zero with error 1428 – Cannot set nonlocal hook without a module handle(ERROR_HOOK_NEEDS_HMOD).
So it seems that there is something wrong with hModule.

Any suggestions?
Tnx.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T06:46:01+00:00Added an answer on May 27, 2026 at 6:46 am

    You cannot inject a managed assembly into a process. A native DLL is required, written in a language like C, C++ or Delphi. This project might be useful as a source for the DLL you’ll need.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can hook my app into the Share page feature using the following intent-filter:
How we can hook up a code inside a python process so that it
I'm wondering how I can hook up an input type=file to send a picture
How can I hook up an event to a function name I have defined
If I create a Google apps script, can I hook it up to Google
Castle Validator uses attributes to specify validation rules. How can you hook these up
can anyone give me some tips or hook me up with some good links
Can anyone tell me how to hook/overlay a DirectX game in C#? I've tried
I can correctly setup up a windows hook, but I get confused by the
I can't do use git post-update hook to pull into my website folder, from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.