MCPcopy Create free account
hub / github.com/mhammond/pywin32 / ReportAPIError

Function ReportAPIError

win32/src/PythonService.cpp:1373–1395  ·  view source on GitHub ↗

Code that exists in both EXE and DLL - mainly error handling code. * * * Error and Event Log related functions. * * *************************************************************************/

Source from the content-addressed store, hash-verified

1371 *
1372 *************************************************************************/
1373static void ReportAPIError(DWORD msgCode, DWORD errCode /*= 0*/)
1374{
1375 if (errCode==0)
1376 errCode = GetLastError();
1377
1378 const int bufSize = 512;
1379 TCHAR buf[bufSize];
1380 BOOL bHaveMessage = (::FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, errCode, 0, buf, bufSize, NULL )>0);
1381 if (!bHaveMessage)
1382 _tcscpy(buf,TEXT("No error message is available"));
1383 /* strip trailing cr/lf */
1384 int end = _tcslen(buf)-1;
1385 if (end>1 && (buf[end-1]==L'\n' || buf[end-1]==L'\r'))
1386 buf[end-1] = L'\0';
1387 else
1388 if (end>0 && (buf[end]==L'\n' || buf[end]==L'\r'))
1389 buf[end]=L'\0';
1390
1391 TCHAR cvtBuf[20];
1392 wsprintf(cvtBuf, L"%d", errCode);
1393 LPTSTR lpszStrings[] = {cvtBuf, buf, L'\0'};
1394 ReportError(msgCode, (LPCTSTR *)lpszStrings);
1395}
1396
1397static void ReportPythonError(DWORD code)
1398{

Callers 3

service_mainFunction · 0.85
PythonService_mainFunction · 0.85

Calls 2

ReportErrorFunction · 0.85
FormatMessageClass · 0.50

Tested by

no test coverage detected