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

Function LoadPythonServiceInstance

win32/src/PythonService.cpp:1245–1280  ·  view source on GitHub ↗

Given a Python class and an "argv" array, instantiate our instance.

Source from the content-addressed store, hash-verified

1243// Given a Python class and an "argv" array, instantiate our
1244// instance.
1245PyObject *LoadPythonServiceInstance( PyObject *pyclass,
1246 DWORD dwArgc,
1247 LPTSTR *lpszArgv )
1248{
1249 if (pyclass==NULL) {
1250 ReportPythonError(PYS_E_BAD_CLASS);
1251 return NULL;
1252 }
1253 PyObject *args = PyTuple_New(dwArgc);
1254 if (args==NULL) {
1255 Py_DECREF(pyclass);
1256 ReportPythonError(PYS_E_NO_MEMORY_FOR_ARGS);
1257 return NULL;
1258 }
1259 for (DWORD i=0;i<dwArgc;i++) {
1260 PyObject *arg = PyWinObject_FromWCHAR(lpszArgv[i]);
1261 if (arg==NULL) {
1262 Py_DECREF(args);
1263 Py_DECREF(pyclass);
1264 ReportPythonError(PYS_E_BAD_ARGS);
1265 return NULL;
1266 }
1267 PyTuple_SET_ITEM(args, i, arg);
1268 }
1269 PyObject *realArgs = PyTuple_New(1);
1270 PyTuple_SET_ITEM(realArgs, 0, args);
1271 PyObject *result = PyObject_CallObject(pyclass, realArgs);
1272 if (result==NULL) {
1273 BOOL bHandledError = PyErr_ExceptionMatches(servicemanager_startup_error);
1274 if (bHandledError)
1275 PyErr_Clear();
1276 else
1277 ReportPythonError(PYS_E_BAD_CLASS);
1278 }
1279 return result;
1280}
1281
1282BOOL LocatePythonServiceClassString( TCHAR *svcName, TCHAR *buf, int cchBuf)
1283{

Callers 1

service_mainFunction · 0.85

Calls 1

ReportPythonErrorFunction · 0.85

Tested by

no test coverage detected