VC debugging technology tips (4)

zhaozj2021-02-16  56

Get system functions error code

The error code returned by a Windows function is often useful why it is often useful. Microsoft compiles a list of all possible error codes and assigns a 32-bit number for each error code. In terms of the internal system, when a Windows function detects an error, it uses the mechanism called thread local memory [2] (thread-local storage), associating the corresponding error code number with the calling thread. . This will make the thread can run independently without affecting their respective error codes. When the function returns, its return value indicates that an error has occurred. To determine this error, you can get the 32-bit error code of the thread by calling the getLastError () function (a DWORD type variable value). When the 32-bit error code is obtained, it must be converted to a useful object, and the Winerror.h header contains the list of error code defined by Microsoft. From this document, there are three representations: a message ID, message text, and a number, the specific details can be found in the WINError.h header file.

It is worth noting that when the Windows function fails, it should be called immediately. If other functions are called after a function is running, its error code may be rewritten.

When debugging, the Watch window can be configured in VC6 to always display the number of the error code and the description of the error. To achieve this, you must type "@ Err, HR" on a line of Watch Window. This will always display the error code returned by the currently executed function. As shown below:

转载请注明原文地址:https://www.9cbs.com/read-22011.html

New Post(0)