Convert NTSTATUS code to Win32 error source codeThis snippet submitted by Ian Abbott on 2012-02-24. It has been viewed 3505 times.Rating of 8.7 with 23 votes /*
* This is an alternative to the RtlNtStatusToDosError()
* function in ntdll.dll. It uses the GetOverlappedResult()
* function in kernel32.dll to do the conversion.
*/
#include <windows.h>
DWORD
ConvertNtStatusToWin32Error(LONG ntstatus)
{
DWORD oldError;
DWORD result;
DWORD br;
OVERLAPPED o;
o.Internal = ntstatus;
o.InternalHigh = 0;
o.Offset = 0;
o.OffsetHigh = 0;
o.hEvent = 0;
oldError = GetLastError();
GetOverlappedResult(NULL, &o, &br, FALSE);
result = GetLastError();
SetLastError(oldError);
return result;
}
More C and C++ source code snippets Add a snippet! |