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

Function PyLogMsg

win32/src/PythonService.cpp:194–251  ·  view source on GitHub ↗

@pymethod |servicemanager|LogMsg|Logs a specific message

Source from the content-addressed store, hash-verified

192
193// @pymethod |servicemanager|LogMsg|Logs a specific message
194static PyObject *PyLogMsg(PyObject *self, PyObject *args)
195{
196 PyObject *obStrings;
197 WORD errorType;
198 DWORD code;
199 LPCTSTR *pStrings = NULL;
200 PyObject *rc = NULL;
201 Py_ssize_t numStrings = 0;
202 BOOL ok = FALSE;
203
204 // @pyparm int|errorType||
205 // @pyparm int|eventId||
206 // @pyparm (string, )|inserts|None|
207 if (!PyArg_ParseTuple(args, "il|O:LogMsg", &errorType, &code, &obStrings))
208 return NULL;
209
210 if (obStrings==Py_None) {
211 pStrings = NULL;
212 } else if (PySequence_Check(obStrings)) {
213 numStrings = PySequence_Length(obStrings);
214 pStrings = new LPCTSTR [numStrings+1];
215 if (pStrings==NULL) {
216 PyErr_SetString(PyExc_MemoryError, "Allocating string arrays");
217 goto cleanup;
218 }
219 memset(pStrings, 0, sizeof(TCHAR *)*(numStrings+1)); // this also terminates array!
220 for (Py_ssize_t i=0;i<numStrings;i++) {
221 PyObject *obString = PySequence_GetItem(obStrings, i);
222 if (obString==NULL) {
223 goto cleanup;
224 }
225 BOOL ok = PyWinObject_AsTCHAR(obString, (LPTSTR *)(pStrings+i));
226 Py_XDECREF(obString);
227 if (!ok)
228 goto cleanup;
229 }
230 } else {
231 PyErr_SetString(PyExc_TypeError, "strings must be None or a sequence");
232 goto cleanup;
233 }
234 Py_BEGIN_ALLOW_THREADS
235 ok = ReportError(code, pStrings, errorType);
236 Py_END_ALLOW_THREADS
237 if (ok) {
238 Py_INCREF(Py_None);
239 rc = Py_None;
240 } else
241 PyWin_SetAPIError("RegisterEventSource/ReportEvent");
242
243cleanup:
244 if (pStrings) {
245 for (int i=0;i<numStrings;i++)
246 PyWinObject_FreeTCHAR((LPTSTR)pStrings[i]);
247 delete [] pStrings;
248 }
249 return rc;
250
251}

Callers

nothing calls this directly

Calls 1

ReportErrorFunction · 0.85

Tested by

no test coverage detected