"Windows Core Programming" Reading Notes (2)

xiaoxiao2021-03-06  77

Chapter 1 programmer must read 1.1 Define your own error code

If you have written a function that you want to call others, your function may fail because there is such a reason, you have to indicate that it has failed to indicate the caller of the function. To specify the function of the function, you only need to set the last error code of the thread, and then let your function returns false, invalid_handle_value, null, or returns any suitable information. The last error code of the thread can be set by VIOD SetLastError (DWORD DWERRCODE);

1.2 ERRORSHOW Example Apparatus FormatMessage Function Usage // Get Error Code DWORD DWERROR = Getdlgitemint (HWND, Idc_ERRORCODE, NULL, FALSE); HLOCAL HLOCAL = NULL; // Create a buffer that stores the wrong text and initialize; // Get Error Code text description BOOL fOK = ForMatMessage (FORMAT_MASSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER, NULL, dwError, MAKELANGID (LANG_ENGLISH, SUBLANG_ENGLISH_US), (LPTSTR) & hlocal, 0, NULL); ........... if (hloca = NULL! ) {SetDlgItemText (hwnd, IDC_ERRORTEXT, (PCTSTR) LocalLock (hlocal)); LocalFree (hlocal);} else {SetDlgItemText (hwnd, IDC_ERRORTEXT, TEXT ( "Error number not found"));} when calling FormatMessage function, passing The format_message_from_system flag. This flag tells the formatMessage function, we want the system to define the string of the error code. The Format_Message_allocate_buffer flag is also passed to tell the function to allocate a large enough memory block for the text description of the error code. The handle of the memory block returns the HLOCAL variable. The third parameter indicates the number of the error code you want to find, and the fourth parameter indicates what language you want to use.

November 9, 2004

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

New Post(0)