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

Function ReportError

win32/src/PythonService.cpp:1474–1530  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1472}
1473
1474static BOOL ReportError(DWORD code, LPCTSTR *inserts, WORD errorType /* = EVENTLOG_ERROR_TYPE*/)
1475{
1476 WORD numInserts = 0;
1477 while (inserts && inserts[numInserts]!=NULL)
1478 numInserts++;
1479
1480 HANDLE hEventSource;
1481 // Use event logging to log the error.
1482
1483 if (bServiceDebug) {
1484 TCHAR *szType;
1485 switch (errorType) {
1486 case EVENTLOG_WARNING_TYPE:
1487 szType = _T("Warning");
1488 break;
1489 case EVENTLOG_INFORMATION_TYPE:
1490 szType = _T("Info");
1491 break;
1492 case EVENTLOG_ERROR_TYPE:
1493 szType = _T("Error");
1494 break;
1495 default:
1496 szType = _T("Message");
1497 break;
1498 }
1499 LPTSTR buffer;
1500 // Get the message text, and just print it.
1501 if (FormatMessage(FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_ARGUMENT_ARRAY,
1502 g_hdll, code, 0, (LPTSTR)&buffer, 0, (va_list *)inserts)==0) {
1503 _tprintf(_T("%s 0x%X - No message available\nMessage inserts were"), szType, code);
1504 for (int i=0;i<numInserts;i++)
1505 _tprintf(_T("'%s',"), inserts[i]);
1506 } else {
1507 _tprintf(_T("%s 0x%X - %s"), szType, code, buffer);
1508 LocalFree(buffer);
1509 }
1510 return TRUE;
1511 } else {
1512 CheckRegisterEventSourceFile();
1513 hEventSource = RegisterEventSource(NULL, g_szEventSourceName);
1514 if (hEventSource==NULL)
1515 return FALSE;
1516
1517 BOOL rc = ReportEvent(hEventSource, // handle of event source
1518 errorType, // event type
1519 0, // event category
1520 code, // event ID
1521 NULL, // current user's SID
1522 numInserts, // strings in lpszStrings
1523 0, // no bytes of raw data
1524 inserts, // array of error strings
1525 NULL); // no raw data
1526
1527 (VOID) DeregisterEventSource(hEventSource);
1528 return rc;
1529 }
1530}
1531

Callers 6

DoLogMessageFunction · 0.85
PyLogMsgFunction · 0.85
service_mainFunction · 0.85
LoadPythonServiceClassFunction · 0.85
ReportAPIErrorFunction · 0.85
ReportPythonErrorFunction · 0.85

Calls 3

ReportEventFunction · 0.85
FormatMessageClass · 0.50

Tested by

no test coverage detected