48 TCHAR fileBuf[MAX_PATH];
49 static const char *fileName = NULL;
51 void __cdecl DebugMsg(
const char* pszFormat, ...)
56 sprintf(buf,
"[%s](%lu): ",
SERVICENAME, GetCurrentThreadId());
57 va_start(arglist, pszFormat);
58 vsprintf(&buf[strlen(buf)], pszFormat, arglist);
62 if ( fileName == NULL )
64 SHGetFolderPath(NULL, CSIDL_COMMON_DOCUMENTS | CSIDL_FLAG_CREATE, NULL, 0, fileBuf);
65 PathAppend(fileBuf,
"clientApi.log");
69 stream = fopen(fileName,
"a+");
72 fwrite(buf, 1, strlen(buf), stream);
79 #define SERVICENAME "RXAPI"
105 SERVICE_STATUS_PROCESS ssp;
108 if ( QueryServiceStatusEx(hService, SC_STATUS_PROCESS_INFO, (LPBYTE)&ssp,
sizeof(SERVICE_STATUS_PROCESS), &needed) == 0 )
113 if ( ssp.dwCurrentState == SERVICE_RUNNING || ssp.dwCurrentState == SERVICE_STOPPED ||
114 ssp.dwCurrentState == SERVICE_STOP_PENDING )
116 return ssp.dwCurrentState == SERVICE_RUNNING;
120 uint32_t startTicks = GetTickCount();
121 uint32_t oldCheck = ssp.dwCheckPoint;
126 while ( ssp.dwCurrentState == SERVICE_START_PENDING )
134 waitTime = ssp.dwWaitHint / 10;
140 else if ( waitTime > 10000 )
147 BOOL success = QueryServiceStatusEx(hService, SC_STATUS_PROCESS_INFO, (LPBYTE)&ssp,
sizeof(SERVICE_STATUS_PROCESS), &needed);
148 if ( ! success || ssp.dwCurrentState == SERVICE_RUNNING )
153 if ( ssp.dwCheckPoint > oldCheck )
156 startTicks = GetTickCount();
157 oldCheck = ssp.dwCheckPoint;
161 if( (GetTickCount() - startTicks) > ssp.dwWaitHint )
170 return ssp.dwCurrentState == SERVICE_RUNNING ? true :
false;
188 SC_HANDLE hService = NULL;
191 SC_HANDLE hSCM = OpenSCManager(NULL, SERVICES_ACTIVE_DATABASE, SC_MANAGER_CONNECT);
195 hService = OpenService(hSCM,
SERVICENAME, SERVICE_QUERY_CONFIG | SERVICE_QUERY_STATUS);
199 LPQUERY_SERVICE_CONFIG serviceCfg = (LPQUERY_SERVICE_CONFIG)LocalAlloc(LPTR, 4096);
204 if ( QueryServiceConfig(hService, serviceCfg, 4096, &needed) )
206 if ( serviceCfg->dwStartType == SERVICE_DISABLED )
211 LocalFree(serviceCfg);
220 CloseServiceHandle(hService);
234 CloseServiceHandle(hSCM);
250 CloseServiceHandle(hService);
275 SC_HANDLE hSCM = NULL;
286 CloseServiceHandle(hSCM);
292 SC_HANDLE hService = OpenService(hSCM,
SERVICENAME, SERVICE_QUERY_CONFIG | SERVICE_START | SERVICE_QUERY_STATUS);
293 if ( hService == NULL )
299 CloseServiceHandle(hSCM);
304 bool hasStarted =
false;
306 if ( ! StartService(hService, 0, NULL) )
314 CloseServiceHandle(hSCM);
315 CloseServiceHandle(hService);
328 char apiExeName[] =
"RXAPI.EXE";
329 LPCTSTR lpszImageName = NULL;
330 LPTSTR lpszCommandLine = NULL;
331 LPSECURITY_ATTRIBUTES
333 LPSECURITY_ATTRIBUTES
337 BOOL fInheritHandles = FALSE;
338 DWORD fdwCreate = DETACHED_PROCESS;
339 LPVOID lpvEnvironment = NULL;
341 LPCTSTR lpszCurDir = szSysDir;
342 LPSTARTUPINFO lpsiStartInfo;
343 STARTUPINFO siStartInfo;
344 LPPROCESS_INFORMATION lppiProcInfo;
345 PROCESS_INFORMATION MemMgrProcessInfo;
346 lppiProcInfo = &MemMgrProcessInfo;
348 siStartInfo.cb =
sizeof(siStartInfo);
349 siStartInfo.lpReserved = NULL;
350 siStartInfo.lpDesktop = NULL;
351 siStartInfo.lpTitle = NULL;
354 siStartInfo.dwXSize = 0;
355 siStartInfo.dwYSize = 0;
356 siStartInfo.dwXCountChars = 0;
357 siStartInfo.dwYCountChars = 0;
358 siStartInfo.dwFillAttribute = 0;
359 siStartInfo.dwFlags = 0;
360 siStartInfo.wShowWindow = 0;
361 siStartInfo.cbReserved2 = 0;
362 siStartInfo.lpReserved2 = NULL;
363 siStartInfo.hStdInput = NULL;
364 siStartInfo.hStdOutput = NULL;
365 siStartInfo.hStdError = NULL;
366 lpsiStartInfo = &siStartInfo;
367 lpszCommandLine = apiExeName;
370 if (!GetSystemDirectory(szSysDir, 255))
375 if(!CreateProcess(lpszImageName, lpszCommandLine, lpsaProcess,
376 lpsaThread, fInheritHandles, fdwCreate, lpvEnvironment,
377 lpszCurDir, lpsiStartInfo, lppiProcInfo))
398 DWORD envchars = GetEnvironmentVariable(
"RXQUEUESESSION", (LPTSTR) envbuffer,
MAX_QUEUE_NAME_LENGTH);
401 sscanf(envbuffer,
"%p", (
void **)&sessionQueue);
417 sprintf(envbuffer,
"%p", (
void *)sessionQueue);
418 SetEnvironmentVariable(
"RXQUEUESESSION", (LPTSTR) envbuffer);
static void setActiveSessionQueue(QueueHandle sessionQueue)
static void startServerProcess()
static bool getActiveSessionQueue(QueueHandle &sessionQueue)
#define MAX_QUEUE_NAME_LENGTH
bool startAsService(void)
static WinServiceStatusT getServiceStatus(SC_HANDLE *phSCM)
static bool hasServiceStarted(SC_HANDLE hService)