Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
Windos
win32.3rdparty
win32.directx.audio
win32.directx.ddk
win32.directx.graphics
win32.directx.input
win32.directx.managed
win32.directx.misc
win32.directx.networking
win32.directx.sdk
win32.directx.video
win32.dirx.grap.shaders
win32.gdi
win32.international
win32.kernel
win32.messaging
win32.mmedia
win32.networks
win32.ole
win32.rtc
win32.tapi
win32.tapi.beta
win32.tools
win32.ui
win32.wince
win32.wmi
windows.mediacenter
winfx.aero
winfx.announcements
winfx.avalon
winfx.collaboration
winfx.fundamentals
winfx.general
winfx.indigo
winfx.sdk
winfx.winfs
  
 
date: Mon, 7 Jul 2008 06:57:05 -0700,    group: microsoft.public.win32.programmer.ui        back       


Is SetWindowHookEx reentrant (with MessageBox????) ??? or is it a   
I am using Windows Hook (type =  WH_GETMESSAGE) and it seems that it is 
reentrant. I'd like to check, because I don't see this kind of information at 
the documentation.

I make a test application that just call SetWindowsHookEx(..);

On my WindowProc(..) I call 3 times the PostMessage(..) function with wParam 
= 1, 2 and  3.

For my surprise, If I call MessageBox(..) inside my HookProc function, its 
works like a reentrant function. All the calls stops at MessageBox 
isntruction pointer and it processos first the last PostMessage sent 
(wparam=3), after that wparam=2 and the last one wParam=1. Is it really a 
message queue or a message stack??

My codes segments:

installing the hook:


    g_hHook = SetWindowsHookEx( WH_GETMESSAGE, MyGetProc, hInstance, 
GetCurrentThreadId( ) );  
 
  

the window proc:

    case WM_COMMAND:   
        wmId    = LOWORD(wParam);   
  
        // Parse the menu selections:   
        switch (wmId)   
        {   
            case IDM_MYTEST:   
  
                PostMessage( hWnd, WM_MYTEST, 1, 0 );   
                PostMessage( hWnd, WM_MYTEST, 2, 0 );   
                PostMessage( hWnd, WM_MYTEST, 3, 0 );   
                break;   
[...]  

the HookProc:

LRESULT CALLBACK MyGetProc( int code, WPARAM wParam, LPARAM lParam )   
{   
    MSG *msg = (MSG *)lParam;   
    TCHAR szLog[512];   
  
    if( code == HC_ACTION )   
    {   
        if( msg->message == WM_MYTEST )   
        {   
            _sntprintf_s( szLog, sizeof(szLog)/sizeof(TCHAR), _TRUNCATE, _T( 
"WM_MYTEST: %d" ), msg->wParam );   
            MessageBox( msg->hwnd, szLog, _T("test"), MB_OK );   
            MessageBeep( MB_ICONEXCLAMATION );   
        }   
    }   
    return CallNextHookEx( g_hHook, code, wParam, lParam );   
}  

The output:
When the Menu is selected and the 3 PostMessages called, I receive 3 
messageboxes with ids 3, 2, 1. I expected receive the 3 MessageBoxes, but ids 
1, 2, 3

When I execute the code in debug mode, the code is breaked at MessageBox 
call and the instruction pointer goes to the begin of MyGetProc(..). On the 
last MessageBox(..) it continues and goes on, after that it go on with wParam 
=2, and the last one...

Anybody here can explain me why this kind of behaviour?? If I do not call 
MessageBox(..) the HookProc works as expected. It will call the HookProc in 
the correct order and waits the end of one call to start anothers.

If I change the code to this:
LRESULT CALLBACK MyGetProc( int code, WPARAM wParam, LPARAM lParam )   
{   
    MSG *msg = (MSG *)lParam;   
    TCHAR szLog[512];   
  
    if( code == HC_ACTION )   
    {   
        if( msg->message == WM_MYTEST )   
        {   
            MessageBeep( MB_ICONEXCLAMATION );   
        }   
    }   
    return CallNextHookEx( g_hHook, code, wParam, lParam );  

and checked out how it work in debugger..

Any explanation will be excelent.

Sorry about my english mistakes.

Regards, Guilherme
date: Mon, 7 Jul 2008 06:57:05 -0700   author:   cox

Re: Is SetWindowHookEx reentrant (with MessageBox????) ??? or is it a   
Answered in microsoft.public.vc.language. Please, don't multipost. 
Crosspost instead.

Alex
date: Mon, 7 Jul 2008 19:04:52 +0300   author:   Alex Blekhman

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us