Exemple #1
0
void __stdcall ServiceMain(int argc, char **argv) {
  ServiceHandle = RegisterServiceCtrlHandler(service, (void (__stdcall *)(unsigned long))ServiceControl);
  ServiceStatus(SERVICE_RUNNING);
  CreateJVM();
  InvokeMethod("serviceStart", ConvertStringArray(g_env, argc, argv), "([Ljava/lang/String;)V");
  (*g_jvm)->DestroyJavaVM(g_jvm);
}
int APIENTRY _tWinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow)
{
	UNREFERENCED_PARAMETER(hPrevInstance);
	UNREFERENCED_PARAMETER(lpCmdLine);

	hInst = hInstance;

	if (!CheckSingleInstance()) return 1;
	
	HANDLE hSplashBitmap = static_cast<HBITMAP>(LoadImage(hInst, MAKEINTRESOURCE(IDB_SPLASH), IMAGE_BITMAP, 0, 0, 0));
	if (hSplashBitmap)
	{
		CreateThread(NULL, 0, SplashScreenThread, hSplashBitmap, 0, NULL);
	}

	if (!LocateJVM()) return 1;
	if (!LoadVMOptions()) return 1;
	if (!LoadJVMLibrary()) return 1;
	if (!CreateJVM()) return 1;
	if (!RunMainClass()) return 1;

	jvm->DestroyJavaVM();

	terminating = true;
	SetEvent(hEvent);
	WaitForSingleObject(hSingleInstanceWatcherThread, INFINITE);
	CloseHandle(hEvent);
	CloseHandle(hFileMapping);

	return 0;
}
Exemple #3
0
/** Invokes the main method in a new thread. */
int JavaStart(void *ignore) {
  CreateJVM();

  char **argv = g_argv;
  int argc = g_argc;
  //skip argv[0]
  argv++;
  argc--;
  InvokeMethod(method, ExpandStringArray(g_env, ConvertStringArray(g_env, argc, argv)), "([Ljava/lang/String;)V");

  (*g_jvm)->DestroyJavaVM(g_jvm);  //waits till all threads are complete

  return 1;
}
int APIENTRY _tWinMain(HINSTANCE hInstance,
                       HINSTANCE hPrevInstance,
                       LPTSTR    lpCmdLine,
                       int       nCmdShow)
{
    UNREFERENCED_PARAMETER(hPrevInstance);

    hInst = hInstance;

    if (__argc == 2 && _wcsicmp(__wargv[0], _T("SPLASH")) == 0)
    {
        HBITMAP hSplashBitmap = static_cast<HBITMAP>(LoadImage(hInst, MAKEINTRESOURCE(IDB_SPLASH), IMAGE_BITMAP, 0, 0, 0));
        if (hSplashBitmap)
        {
            parentProcId = _wtoi(__wargv[1]);
            parentProcHandle = OpenProcess(SYNCHRONIZE, FALSE, parentProcId);
            if (IsParentProcessRunning(parentProcHandle)) SplashScreen(hSplashBitmap);
        }
        CloseHandle(parentProcHandle);
        return 0;
    }

    //it's OK to return 0 here, because the control is transferred to the first instance
    if (!CheckSingleInstance()) return 0;

    if (nativesplash = wcsstr(lpCmdLine, _T("/nativesplash")) != NULL) StartSplashProcess();

    if (!LocateJVM()) return 1;
    if (!LoadVMOptions()) return 1;
    if (!LoadJVMLibrary()) return 1;
    if (!CreateJVM()) return 1;

    hSingleInstanceWatcherThread = CreateThread(NULL, 0, SingleInstanceThread, NULL, 0, NULL);

    if (!RunMainClass()) return 1;

    jvm->DestroyJavaVM();

    terminating = true;
    SetEvent(hEvent);
    WaitForSingleObject(hSingleInstanceWatcherThread, INFINITE);
    CloseHandle(hEvent);
    CloseHandle(hFileMapping);

    return 0;
}