DWORD iErrorValue;
while(std::cin>>iErrorValue)
{
HLOCAL hlocal = NULL; // Buffer that gets the error message string
// Use the default system locale since we look for Windows messages.
// Note: this MAKELANGID combination has 0 as value
DWORD systemLocale = MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL);
// Get the error code's textual description
BOOL fOk = FormatMessage(
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS |
FORMAT_MESSAGE_ALLOCATE_BUFFER,
NULL, iErrorValue, systemLocale,
(PTSTR) &hlocal, 0, NULL);
const WCHAR *errString = (PCTSTR)LocalLock(hlocal);
std::wstring wsError(errString);
LocalFree(hlocal);
}
HANDLE hFile = CreateFile(TEXT("C:\\jeff"), 0, 0 , NULL, OPEN_EXISTING, 0, NULL);
if (hFile == INVALID_HANDLE_VALUE)
{
std::cout<<"Create file failed\n";
}
DWORD iErrValue = GetLastError();
std::cout<<iErrValue<<std::endl;
return 0;
while(std::cin>>iErrorValue)
{
HLOCAL hlocal = NULL; // Buffer that gets the error message string
// Use the default system locale since we look for Windows messages.
// Note: this MAKELANGID combination has 0 as value
DWORD systemLocale = MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL);
// Get the error code's textual description
BOOL fOk = FormatMessage(
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS |
FORMAT_MESSAGE_ALLOCATE_BUFFER,
NULL, iErrorValue, systemLocale,
(PTSTR) &hlocal, 0, NULL);
const WCHAR *errString = (PCTSTR)LocalLock(hlocal);
std::wstring wsError(errString);
LocalFree(hlocal);
}
HANDLE hFile = CreateFile(TEXT("C:\\jeff"), 0, 0 , NULL, OPEN_EXISTING, 0, NULL);
if (hFile == INVALID_HANDLE_VALUE)
{
std::cout<<"Create file failed\n";
}
DWORD iErrValue = GetLastError();
std::cout<<iErrValue<<std::endl;
return 0;