-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adde platform::windows::GetLastErrorToString()
- Loading branch information
1 parent
c062190
commit f85ce31
Showing
2 changed files
with
41 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#pragma once | ||
|
||
#include <string> | ||
|
||
#if defined(_WIN32) | ||
#ifndef WIN32_LEAN_AND_MEAN | ||
#define WIN32_LEAN_AND_MEAN | ||
#endif | ||
#ifndef NOMINMAX | ||
#define NOMINMAX | ||
#endif | ||
#include <Windows.h> | ||
#endif | ||
|
||
|
||
namespace platform::windows | ||
{ | ||
std::string GetLastErrorToString(DWORD error) | ||
{ | ||
#if defined(_WIN32) | ||
if (error != 0) | ||
{ | ||
char *formatedMessage = nullptr; | ||
DWORD formatedMessageSize = FormatMessageA( | ||
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, | ||
nullptr, error, 0, (char *)&formatedMessage, 0, nullptr); | ||
|
||
if (formatedMessage != nullptr && formatedMessageSize > 0) | ||
{ | ||
std::string result(formatedMessage, formatedMessageSize); | ||
LocalFree(formatedMessage); | ||
return result; | ||
} | ||
} | ||
#endif | ||
return std::string(); | ||
} | ||
} |