How to call GetLastError in the Debugger (Visual Studio)

Every time I debug with someone else at their machine, they are surprised by this little trick.  So I will post it here.

In Windows programming, you often have Win32 calls which return an error, and you then need to call GetLastError() in order to find the real error number.  If you are in the debugger, you don’t need to modify your code to call GetLastError at that point. 

Instead, just add “@err” or “@err,hr” to your debug watch window.  Now it’s more like looking at errno.

One Response to “How to call GetLastError in the Debugger (Visual Studio)”

  1. Dennis P. Nikolaenko Says:

    Nice trick, indeed!
    Your post helped me to recall it after the 2 year period of non coding on Cpp

Leave a Reply