MCPcopy Create free account
hub / github.com/DiscordMessenger/dm / GetTStringFromHResult

Function GetTStringFromHResult

src/windows/WinUtils.cpp:161–189  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

159}
160
161LPTSTR GetTStringFromHResult(HRESULT hr)
162{
163 LPCTSTR tstr = NULL;
164 FormatMessage(
165 FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS,
166 NULL,
167 hr,
168 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
169 (LPTSTR)&tstr,
170 0,
171 NULL
172 );
173
174 bool bFree = true;
175 if (!tstr) {
176 bFree = false;
177 tstr = TEXT("Unknown Error Code");
178 }
179
180 // dupe it to be able to use free() instead of LocalFree()
181 size_t newSz = _tcslen(tstr);
182 TCHAR* newStr = new TCHAR[newSz + 1];
183 _tcscpy(newStr, tstr);
184
185 if (bFree)
186 LocalFree((HLOCAL) tstr);
187
188 return newStr;
189}
190
191std::string GetStringFromHResult(HRESULT hr)
192{

Callers 2

GetStringFromHResultFunction · 0.85
DownloadFileResponseFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected