I am trying to debug a very old C program in visual studio. I was stepping through some code line by line and came to a line DispatchMessage(&msg); I wanted to see where the code went next, so I clicked the “Step into” button, but I was not taken to any new code that processed the message, instead the little yellow arrow just stepped along to the next line down the same page…
Is this expected behaviour? How can I see what DispatchMessage actually did?
Could this be an indication that the window handler is not set up correctly?
extra info: The task I was tring to debug was the processing of a mouse click on a particular window. I had displayed the msg structure, and msg.hwnd was the window I had clicked on (I used Winspector to confirm). The msg.message was 513 (=WM_LBUTTONDOWN).
This is completely expected behaviour…
DispatchMessage()is implemented inUser32.dlland as such, the source code is not available. For the most part, you have to treat Win32 API calls as blackboxes. At times, this can really make debugging Win32 code a challenge.Remember, there are some tricks in your arsenal for debugging this kind of thing:
Go on treating
DispatchMessage()as a black box. Place a breakpoint on theWndProcyou expect to receive theWM_LBUTTONDOWNand continue debugging there.Have Winspector log the messages coming into all of the windows involved. This can help make sure the message is received and in the order you are expecting.
If worst comes to worst, you may have to step into
DispatchMessage()or some other API call, looking at its disassembly. Most of the time, nothing good comes from that (but I always learn something when I do).Chances are that option #3 won’t be necessary and your time would be better spent debugging around
DispatchMessage()rather than within it.