Last active
December 19, 2022 13:16
-
-
Save ian-abbott/732c5b88182a1941a603 to your computer and use it in GitHub Desktop.
C function to convert an NTSTATUS code into a Win32 error code - alternative to RtlNtStatusToDosError()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <windows.h> | |
/* | |
* This is an alternative to the RtlNtStatusToDosError() | |
* function in ntdll.dll. It uses the GetOverlappedResult() | |
* function in kernel32.dll to do the conversion. | |
*/ | |
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; | |
} |
You are right, it is working well now. Don't know what it was recently, always returned 87.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@sergio-nsk GetOverlappedResult is expected to fail. ConvertNtStatusToWin32Error(0xC0000022L) should return 5, mapping STATUS_ACCESS_DENIED to ERROR_ACCESS_DENIED.