This article describes the VC + + through the API to view the error information method, you can encounter errors, will display error messages and exit processing, the specific implementation code as follows:
if (m_hbitmap= (HBITMAP):: LoadImage (null,filepath,image_bitmap,0,0,lr_defaultsize|
Lr_loadfromfile) ==null) {lpvoid lpmsgbuf;
DWORD DW =:: GetLastError ();
FormatMessage (Format_message_allocate_buffer |
Format_message_from_system |
Format_message_ignore_inserts, NULL, DW, Makelangid (Lang_neutral, Sublang_default), (LPTSTR) &lpmsgbuf, 0, NULL);
Displays an error message and exits the handler:: MessageBox (NULL, (LPCTSTR) lpmsgbuf,text ("ERROR"), Mb_iconerror);
LocalFree (LPMSGBUF);
Return } if (m_hbitmap= (HBITMAP):: LoadImage (null,filepath,image_bitmap,0,0,lr_defaultsize|
Lr_loadfromfile) ==null) {lpvoid lpmsgbuf;
DWORD DW =:: GetLastError ();
FormatMessage (Format_message_allocate_buffer |
Format_message_from_system |
Format_message_ignore_inserts, NULL, DW, Makelangid (Lang_neutral, Sublang_default), (LPTSTR) &lpmsgbuf, 0, NULL);
Displays an error message and exits the processing process:: MessageBox (NULL, (LPCTSTR) lpmsgbuf,text ("ERROR"), Mb_iconerror);
LocalFree (LPMSGBUF);
Return
Interested friends can test the effect in the development of the project, hope to help everyone.