CodeProject
We have recently been fighting a weird problem in our .NET application that was caused by a duplicate WM_KEYDOWN
message. It is relatively easy to figure out who receives the message (Spy++ helps a lot), but how to find out who sends it?
If you know (or suspect) the process that sends your message, here’s how to debug it in Visual Studio 2013:
- Run the program you want to debug.
- Attach debugger, make sure native debugger is selected.
- Break into debugger, if it’s not there already.
- Open window Debug->Windows->Modules, load symbols for user32.dll
- Open BreakPoints window.
- Add new break point at each of the functions below. IMPORTANT: Set language to C++ (does not seem to work otherwise).
- Functions:
_PostMessageA@16
, _PostMessageW@16
, _SendMessageA@16
, SendMessageW@16
. - For each breakpoint, set the following condition:
*(int*)(esp+8) == 0x100
- Resume the app and enjoy.
Explanation of the condition:
ESP is the stack pointer
*ESP is the return address
*(ESP+4) is the first parameter, hWnd
*(ESP+8) is the second parameter, uMsg
So, our condition basically amounts to uMsg == WM_KEYDOWN
.
If you want to break on sending a WM_KEYDOWN
message to a specific window handle, you can set the condition like so:
*(int*)(esp+4) == 0xmyhandlehere && *(int*)(esp+8) == 0x100
This article was originally posted at
http://www.ikriv.com/blog?p=1631