-1

I'm loading 3rd party DLLs and sometimes they open MessageBox windows that stops the flow of the application, I want to be able to detect when such thing happens.

I'm trying to use SetWindowsHookEx with WH_CBT but my callback does not get called.

I tried calling it this way:

SetWindowsHookEx (WH_CBT, myCallback, NULL, 0);

But it didn't worked.

What should be the right call for this function?

James M
  • 18,506
  • 3
  • 48
  • 56
kambi
  • 3,291
  • 10
  • 37
  • 58
  • 2
    You are not going to inject a hook by passing NULL and 0 to the function. Improve your error handling, don't ignore api function return values. – Hans Passant Feb 26 '12 at 16:11
  • I also tried SetWindowsHookEx (WH_CBT, myCallback, GetModuleHandle (0), GetCurrentThreadId()) but to no avail. – kambi Feb 26 '12 at 16:23
  • 2
    You are just randomly trying stuff. A global hook like WH_CBT requires a DLL that can be injected into other processes. That will never be GetModuleHandle(0), you cannot inject your own EXE. Visit the google hits, this is well covered. – Hans Passant Feb 26 '12 at 16:33
  • possible duplicate of [Detecting creation of a MessageBox](http://stackoverflow.com/questions/9084579/detecting-creation-of-a-messagebox) Oh wait, you're the person who asked that question. Did you read the documentation I linked to? As Hans says, just randomly trying stuff isn't going to make it work. – Cody Gray - on strike Feb 27 '12 at 18:23
  • Both the answer here and in the other post will work – kambi Mar 15 '12 at 07:49

1 Answers1

0

You may use the WM_ENTERIDLE message to detect if there's any MessageBox window, simply check with FindWindowEx().

This is C# but idea doesn't change: http://social.msdn.microsoft.com/forums/en-US/winforms/thread/d3f89686-e4d0-4bb1-9052-31abef2a9d2a

Adriano Repetti
  • 65,416
  • 20
  • 137
  • 208