Windows function error handling

zhaozj2021-02-11  156

When calling a Windows function, it first wants to verify the validity of each parameter passed, and then try to perform a task. If you pass an invalid parameter, or if this is not performed, the operating system will return. A value indicating that the function has failed to some extent. Windows Functions Common Return Value Type: Void Bool: 0, Non 0, Null, False Handle: Handle, Null, Invalid_Handle_Valid) PVOID: NULL, PVOID LONG / DWORD: Specific functions ... Microsoft compiled a possible Error code list and assign a 32-bit number to each error code. Winerror.h header file (approximately 20,000 rows) contains a list of error code defined by MICORSoft. When a Windows function detects an error, it The thread-local storage mechanism will be used to associate the corresponding error code number with the calling thread. This will cause the thread to run independently, without affecting the respective error code. When the function returns, Its return value indicates whether there is an error. If you have any errors, you need to call the DWORD getLastError () function, it returns the 32-bit error code of the thread. Visual Studio has an Error Lookup program to use the error code The number is replaced with the corresponding text description. Windows also provides a function FormatMessage to convert the error code into its text description .dword formssage (DWORD DWFLAGS, // Source and processing options lpcvoid lpsource, // message source dword dwmessageID, // message identifier DWORD dwLanguageId, // language identifier LPTSTR lpBuffer, // message buffer DWORD nSize, // maximum size of message buffer va_list * Arguments // array of message inserts); we can also use this mechanism in their function, only You need to use the Void SetLastError (DWORD DWERRCODE) function, if any code in WineError.h does not correctly reflect the nature of the error, then you can create your own generation code. Division of the wrong code domain: Bit 31 ~ 30 29 28 27 ~ 16 15 ~ 0 Content Severity Microsoft / Customer Reserved Equipment Code Abnormal Code

Meaning 0 = Success 0 = MS defined code must be 0 by MS definition by ms or customer definition 1 = Reference 2 = Warning 1 = Customer defined code 3 = Error

Note: If you create your own error code, you will make 29 bits of 1.

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

New Post(0)