MCPcopy Create free account
hub / github.com/SafeBreach-Labs/PoolParty / w_FormatMessageA

Function w_FormatMessageA

PoolParty/Misc.cpp:4–33  ·  view source on GitHub ↗

TODO: Move to WinApi.hpp

Source from the content-addressed store, hash-verified

2
3// TODO: Move to WinApi.hpp
4std::string w_FormatMessageA(DWORD dwFlags, LPCVOID lpSource, DWORD dwMessageId, DWORD dwLanguageId, DWORD nSize, va_list* Arguments)
5{
6 LPSTR pErrorText = nullptr;
7
8 auto szErrorText = FormatMessageA(
9 dwFlags,
10 lpSource,
11 dwMessageId,
12 dwLanguageId,
13 reinterpret_cast<LPSTR>(&pErrorText),
14 nSize,
15 Arguments);
16 if (0 == szErrorText)
17 {
18 std::ostringstream oss;
19 oss << "FormatMessageA failed: " << GetLastError();
20 throw std::runtime_error(oss.str());
21 }
22
23 const auto sErrorText = std::string(pErrorText);
24
25 /* if FORMAT_MESSAGE_ALLOCATE_BUFFER is used, the buffer is allocated using LocalAlloc, so after the std::string initialization we should free it */
26 if (dwFlags & FORMAT_MESSAGE_ALLOCATE_BUFFER)
27 {
28 LocalFree(pErrorText);
29 pErrorText = nullptr;
30 }
31
32 return sErrorText;
33}
34
35std::string GetLastErrorString(std::string FailedFunctionName, DWORD dwLastError)
36{

Callers 1

GetLastErrorStringFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected