error.cpp
上传用户:bjlvip
上传日期:2010-02-08
资源大小:744k
文件大小:1k
- // error.cpp
- #include <windows.h>
- #include <stdio.h>
- void ErrorMessage(char* szMessage, HRESULT hr)
- {
- if(HRESULT_FACILITY(hr) == FACILITY_WINDOWS)
- hr = HRESULT_CODE(hr);
- char* szError;
- if(FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM, NULL, hr, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&szError, 0, NULL) != 0)
- {
- printf("%s: %s", szMessage, szError);
- LocalFree(szError);
- }
- else
- printf("Error number not foundn");
- }
- void main(int argc, char** argv)
- {
- if(argc == 2)
- {
- HRESULT hr;
- sscanf(argv[1], "%x", &hr);
- printf("HRESULT = %xn", hr);
- ErrorMessage("Error message", hr);
- }
- else
- printf("Sample usage:nerror 80070057n");
- }