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

Function PythonService_main

win32/src/PythonService.cpp:1078–1180  ·  view source on GitHub ↗

* * * Generic Service Host implementation - handles command-line args, * uses the registry to work out what Python classes to load, etc. * This section could be split into the EXE. * * *************************************************************************/ FUNCTION: PythonService_main PURPOSE: entrypoint for our generic PythonService host PARAMETERS: argc - number of command line argu

Source from the content-addressed store, hash-verified

1076// the service has stopped, so exit.
1077//
1078int PythonService_main(int argc, TCHAR **argv)
1079{
1080 // Note that we don't know the service name we are hosting yet!
1081 // If only one service is hosted, then it is no real problem - our dispatch
1082 // table has a single entry, and this must be our service (and indeed
1083 // Windows doesn't care - it ignores the service name in the dispatch table
1084 // if SERVICE_WIN32_OWN_PROCESS is set.
1085 // However, if we want to host multiple services, we have a problem.
1086 // For now, the solution is to not support multiple services via this
1087 // generic PythonService.exe. However, py2exe etc is free to register
1088 // multiple services (and we don't care how it find out the service names)
1089 // Later, we could add support to the service registration code so that
1090 // the service names are always passed on the command-line (-services=)
1091 // (This is also the reason "-debug" requires the service name on the
1092 // command-line.)
1093 int temp;
1094 LPTSTR *targv;
1095
1096#ifdef UNICODE
1097 targv = CommandLineToArgvW(GetCommandLineW(), &temp);
1098#else
1099 targv = argv;
1100#endif
1101 // Before we start, change directory to our executable's dir. This
1102 // is to prevent our cwd being SYSTEM32, which can have undesired
1103 // side effects (ie, it ends up on sys.path and, eg, 'import zlib' may
1104 // locate zlib.dll in that directory rather than the correct zlib.pyd.
1105 TCHAR dir[MAX_PATH] = _T("");
1106 GetModuleFileName(0, dir, sizeof(dir)/sizeof(dir[0]));
1107 TCHAR *slash = _tcsrchr(dir, _T('\\'));
1108 if (slash) {
1109 *slash = '\0';
1110 _tchdir(dir);
1111 }
1112 // Process the args
1113 if ( (argc > 1) &&
1114 ((*argv[1] == '-') || (*argv[1] == '/')) )
1115 {
1116#ifndef BUILD_FREEZE
1117 if ( _tcsicmp( _T("register"), argv[1]+1 ) == 0 ||
1118 _tcsicmp( _T("install"), argv[1]+1 ) == 0 )
1119 {
1120 // Get out of here.
1121 return RegisterPythonServiceExe() ? 0 : 1;
1122 }
1123#endif
1124 if ( _tcsicmp( _T("debug"), argv[1]+1 ) == 0 ) {
1125 /* Debugging the service. If this EXE has a service name
1126 embedded in it, use it, otherwise insist one is passed on the
1127 command line
1128 (NOTE: Embedding a resource to specify the service name is
1129 deprecated)
1130 */
1131 TCHAR svcNameBuf[256];
1132 TCHAR *svcName;
1133 int argOffset = 1;
1134 if (LoadString(GetModuleHandle(NULL), RESOURCE_SERVICE_NAME, svcNameBuf, sizeof(svcNameBuf)/sizeof(TCHAR))>1) {
1135 svcName = svcNameBuf;

Callers

nothing calls this directly

Calls 7

RegisterPythonServiceExeFunction · 0.85
LoadStringFunction · 0.85
PythonService_InitializeFunction · 0.85
service_mainFunction · 0.85
ReportAPIErrorFunction · 0.85

Tested by

no test coverage detected