MCPcopy Create free account
hub / github.com/CppMicroServices/CppMicroServices / get_error_str

Function get_error_str

tools/rc/ResourceCompiler.cpp:97–127  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

95
96# define PATH_SEPARATOR "\\"
97static std::string
98get_error_str()
99{
100 // Retrieve the system error message for the last-error code
101 LPVOID lpMsgBuf;
102 DWORD dw = GetLastError();
103 std::string errMsg;
104 DWORD rc
105 = FormatMessageA((FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS),
106 NULL,
107 dw,
108 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
109 reinterpret_cast<LPSTR>(&lpMsgBuf),
110 0,
111 NULL);
112 // If FormatMessage fails using FORMAT_MESSAGE_ALLOCATE_BUFFER
113 // it means that the size of the error message exceeds an internal
114 // buffer limit (128 kb according to MSDN) and lpMsgBuf will be
115 // uninitialized.
116 // Inform the caller that the error message couldn't be retrieved.
117 if (rc == 0)
118 {
119 errMsg = "Failed to retrieve error message.";
120 }
121 else
122 {
123 errMsg = reinterpret_cast<LPSTR>(lpMsgBuf);
124 LocalFree(lpMsgBuf);
125 }
126 return errMsg;
127}
128
129std::string
130us_tempfile()

Callers 1

us_tempfileFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected