Co-authored-by: Metehan Tuncbilek <mtuncbilek95@gmail.com> Reviewed-by: Georg Hagen <georg.hagen@madvoxel.com> Co-authored-by: mtuncbilek <metehan.tuncbilek@madvoxel.com> Co-committed-by: mtuncbilek <metehan.tuncbilek@madvoxel.com>
45 lines
1.0 KiB
C++
45 lines
1.0 KiB
C++
/*
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
*/
|
|
|
|
#include "ErrorUtils.hpp"
|
|
|
|
#if defined(_MSC_VER)
|
|
#include "Windows.h"
|
|
#endif
|
|
|
|
namespace OpenVulkano
|
|
{
|
|
#if defined(_MSC_VER)
|
|
std::string ErrorUtils::GetLastErrorMessage()
|
|
{
|
|
// Get the error message ID, if any.
|
|
DWORD errorID = GetLastError();
|
|
if (errorID == 0)
|
|
{
|
|
return std::string();
|
|
}
|
|
|
|
LPSTR messageBuffer = nullptr;
|
|
// Format the error message
|
|
uint64_t size =
|
|
FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
|
|
NULL, errorID, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR) &messageBuffer, 0, NULL);
|
|
|
|
// Buffer it up
|
|
std::string message(messageBuffer, size);
|
|
|
|
// Free the buffer and return the message
|
|
LocalFree(messageBuffer);
|
|
return message;
|
|
}
|
|
#else
|
|
std::string ErrorUtils::GetLastErrorMessage()
|
|
{
|
|
return std::string();
|
|
}
|
|
#endif
|
|
|
|
} |