开发者

Why is wparam changing if i use same message, with same paras?

I am currently trying to implement some code from http://www.codeproject.com/KB/threads/winspy.aspx (subclassing part) into my project but having some problems, i debugged the dll and it seems when i send the exact same message(or so i think) to the hooked thread's hwnd the message appears to be different(i see this thanks to debugging dll file directly trough visual studio).

So from start, i share my custom winregistered mssg for all dll instances.. Here i am writting what i use for bo开发者_Python百科th projects(the one downloaded from site above, and my current one that tries to mimic same strategy)

I first share the message i will register later(in dll process atach) with all dll instances..

#pragma data_seg("Shared")
UINT    WM_HOOKEX = 0;
#pragma data_seg()

Ok so time to register it when dll attaches...

BOOL APIENTRY DllMain( HANDLE hModule, 
                       DWORD  ul_reason_for_call, 
                       LPVOID lpReserved
                     )
{
    if( ul_reason_for_call == DLL_PROCESS_ATTACH ) 
    {
        g_hInstDll = (HINSTANCE) hModule;   
        ::DisableThreadLibraryCalls( g_hInstDll );

        if( WM_HOOKEX==NULL )
            WM_HOOKEX = ::RegisterWindowMessage( _T("WM_HOOKEX_RK") );          
    }

    return TRUE;
} 

And finally after i hook to the thread i send the message

hHook = SetWindowsHookEx( WH_CALLWNDPROC,(HOOKPROC)HookProc,
                                g_hInstDll, GetWindowThreadProcessId(plist,NULL) );

SendMessage( hwnd,WM_HOOKEX,0,1);

Now thanks to VS dll debugging i can inspect how this message is received on the other side, in the case of original "3 ways to inject code" project subclassing part the parameters are

wparam = 1
lparam = 23720848

While in my project

wparam = 0
lparam = 23720824

And it appears that while debugging the procedure doesnt recognize WM_HOOKEX at all, WITH SAME PARAMETERS!

I really dont get this, i register hook with dll process attach with exact same name, except that i am using WM_HOOKEX = ::RegisterWindowMessage( _T("WM_HOOKEX_RK") );" with _T as my project is unicode but i really doubt this matters.

Everything else is 100% same

SendMessage( same hwnd ,same mssg ,0,1);

Any ideas why the other side in my project wont see the correct mssg with correct paras?

Thank you


First question, why are you doing this:

hHook = SetWindowsHookEx( WH_CALLWNDPROC,(HOOKPROC)HookProc,
                            g_hInstDll, GetWindowThreadProcessId(plist,NULL);

Rewrite it as

hHook = SetWindowsHookEx( WH_CALLWNDPROC,HookProc,
                            g_hInstDll, GetWindowThreadProcessId(plist,NULL)); 

What on EARTH gave you the idea that the best way to deal with a type mismatch error was just to cast it? You need to fix the HookProc so it is actually the right kind of function.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜