So I want to put a Breakpoint in a specific API or Windows message.
I don’t find any easy way to do that without writing code in any Delphi version.
Is there a way to do that similar as I can put a breakpoint in memory access?
So I want to put a Breakpoint in a specific API or Windows message.
Share
To stop at any call to an API function, find it in the
implementationsection of Windows.pas (or wherever the function of interest is declared) and set a breakpoint. That takes care of functions you use with load-time dynamic linking. For run-time dynamic linking (LoadLibraryandGetProcAddress), you’ll need a different technique. The variable that gets the result ofGetProcAddresswill hold the address you want to break at, but I don’t know off-hand how to set a breakpoint at that address.Stopping on a Window message is trickier since messages can be retrieved in many places. You’ll have to use conditional breakpoints instead.
To catch most posted messages, you can put a breakpoint in
TApplication.HandleMessageon the first line after the call toPeekMessage. Set the condition to beMsg.Message = x.HandleMessagetakes care of messages posted to the main thread’s message queue for the mainApplication.Runmessage loop as well as the VCL’s modal message loops. Other modal dialogs (such asWindows.MessageBox) won’t use it, though.Observing sent messages is harder because the OS dispatches them to their target window procedures directly. You’ll have to set a breakpoint in the window procedure of every window class you’re interested in. You could get most VCL window classes by putting your conditional breakpoint in
Classes.StdWndProc.Keep in mind that conditional breakpoints can be very slow. They work by the debugger putting an unconditional breakpoint there, and when the OS triggers it, the debugger takes over, checks the condition, and then resumes execution if the conditional fails. That can involve a lot of overhead, switching between the debugger and your application; programs receive lots of messages, so if you can find a way to avoid having the debugger interrupt your program to check every one of them, do it.
If this isn’t feasible for whatever it is you’re trying to debug, then I recommend posting a new question where you describe the problem you’re really trying to solve.