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 3235692
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:32:09+00:00 2026-05-17T17:32:09+00:00

Two questions. 1) I understand this must be an expected outcome but maybe someone

  • 0

Two questions.

1) I understand this must be an expected outcome but maybe someone can tell me what I’m doing wrong; I’m trying to subclass all window classes in a global hook and it works except that I’m not able to close shop as I should and when the program initially registering the hook unregisters the hook and exits, subclassed applications start crashing.

Here’s how I’m trying to do it..

// stores original wndprocs. In the hook dll, outside the shared memory.
map<HWND, WNDPROC> origWndProcs;

// in an EnumWindows callback, executed for all HWND's, also in the hook dll (UWM_REMOVE_HOOK is a registered unique message)
SendMessageTimeout(hWnd, UWM_REMOVE_HOOK, 0, 0, SMTO_ABORTIFHUNG | SMTO_NORMAL, 15000, res);

// Still in the same hook, in the subclassing wndproc..
if (msg == UWM_REMOVE_HOOK) {
   if (origWndProcs.find(hwnd) != origWndProcs.end()) {
      SetWindowLongPtr(hwnd, GWL_WNDPROC, (LONG_PTR)origWndProcs[hwnd]);
   }
}

// clears the hook..
__declspec(dllexport) BOOL ClearHooks(HWND hWnd) {

    BOOL unhooked = UnhookWindowsHookEx(hook) &&
       UnhookWindowsHookEx(kb_hook) &&
       UnhookWindowsHookEx(mouse_hook) && 
       UnhookWindowsHookEx(cbt_hook);

    if(unhooked)
       hWndServer = NULL;
    return unhooked;
}

In DllMain I don’t do anything on DLL_PROCESS_DETACH. Instead, ClearHooks() is called from the program originally registering the hooks and there only after the hook has sent a message signalling that it has executed the EnumWindows operation (restores original wndprocs, see above).

I subclass windows in a WndProc hook; all visible windows that receive a message and whose current wndproc is not the one in the dll, are subclassed.

Basically all (as far as I can tell) applications crash on exit despite the fact that windows do seem to get the wndproc set back to what it was when it was replaced. Anyone have a clue what I might be doing wrong?

2) I need this to intercept WM_MINMAXINFO and modify window maxsize whenever a window is maximized. Unfortunately I can’t do this in the dll but I have to talk with a program to get the size info. So, what’s the best way to talk to that window; I need it to pass back some info so I can modify the structure that came with the original WM_MINMAXINFO message. Will a structure in WM_COPYDATA preserve it’s data until the call to SendMessageTimeout returns?

Thanks

  • 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-17T17:32:09+00:00Added an answer on May 17, 2026 at 5:32 pm

    There are plenty of pain points here. You assume that no other code will subclass the window. And that such code will un-subclass it in the right order. There is no right order, your hooking is quite asynchronous from the program’s execution.

    But, the workaround is simple enough. You are already hooking with SetWindowsHookEx, might as well do one more. WH_CALLWNDPROC or WH_CALLWNDPROCRET, depending on what you want to do.

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

Sidebar

Related Questions

Two questions: Can someone point me to unbiased data that compares .NET performance to
I have two questions: 1) How can I make an array which points to
I actually have two questions regarding the same problem but I think it is
This is a follow-up to two questions I asked a week or so back.
Here are two different questions but I think they are related. When using Git,
I am trying to understand the following example, that is similar (but not equal)
I'm pretty sure this must have been here already, but I didn't find much
I just can't seem to understand how this would work. Question: Given a sequential
Two Questions: Will I get different sequences of numbers for every seed I put
I have two questions. Do realloc() and memcpy() copy the entries in an array

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.