Пример #1
0
int APIENTRY wWinMain(HINSTANCE hInstance,
                      HINSTANCE hPrevInstance,
                      LPTSTR    lpCmdLine,
                      int       nCmdShow)
{
    UNREFERENCED_PARAMETER(hPrevInstance);
    UNREFERENCED_PARAMETER(lpCmdLine);
    breakpad_init();
    setUserPWD();

    CefSettings settings;

#ifdef NDEBUG
    settings.log_severity = LOGSEVERITY_ERROR;
#endif

#ifdef TEST_SINGLE_THREADED_MESSAGE_LOOP
    settings.multi_threaded_message_loop = false;
#else
    settings.multi_threaded_message_loop = true;
#endif
    if(!WindowsVersionOK()) {
        MessageBox(NULL,L"Pea Search only support Window XP, Vista and Win7 .", L"Pea Search Warn",MB_OK);
        return 0;
    }
    CefInitialize(settings);
    InitSchemeTest();
    InitPlugin();
    MyRegisterClass(hInstance);
    if (!InitInstance (hInstance, nCmdShow)) return FALSE;

    if(OleInitialize(NULL)!=S_OK) MessageBox(NULL,L"warn",L"ole init failed.",MB_OK);
    connect_named_pipe();
    SetForegroundWindow(hMainWin);
    SetFocus(hMainWin);
    MSG msg;
    while (GetMessage(&msg, NULL, 0, 0)) {
#ifdef TEST_SINGLE_THREADED_MESSAGE_LOOP
        // Allow the CEF to do its message loop processing.
        CefDoMessageLoopWork();
#endif
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    close_named_pipe();
    OleUninitialize();
    CefShutdown();
    return (int) msg.wParam;
}
Пример #2
0
int _tmain (int argc, LPTSTR argv [])
{
    BOOL exitFlag = FALSE;
    TCHAR command [MAX_COMMAND_LINE+10], *pc;
    DWORD i, locArgc; /* Local argc */
    TCHAR argstr [MAX_ARG] [MAX_COMMAND_LINE];
    LPTSTR pArgs [MAX_ARG];

    if (!WindowsVersionOK (3, 1))
        ReportError (_T("This program requires Windows NT 3.1 or greater"), 1, FALSE);

    debug = (argc > 1); /* simple debug flag */
    /*  Prepare the local "argv" array as pointers to strings */
    for (i = 0; i < MAX_ARG; i++) pArgs[i] = argstr[i];

    /*  Open the SC Control Manager on the local machine,
    	with the default database, and all access. */
    hScm = OpenSCManager (NULL, SERVICES_ACTIVE_DATABASE, SC_MANAGER_ALL_ACCESS);
    if (hScm == NULL) ReportError (_T("Cannot open SC Manager"), 1, TRUE);

    /*  Main command proceesing loop  */
    _tprintf (_T("\nWindows Service Management"));
    while (!exitFlag)
    {
        _tprintf (_T("\nSM$"));
        _fgetts (command, MAX_COMMAND_LINE, stdin);
        /*  Replace the new line character with a string end. */
        pc = _tcschr (command, _T('\n'));
        *pc = _T('\0');

        if (debug) _tprintf (_T("%s\n"), command);
        /*  Convert the command to "argc, argv" form. */
        GetArgs (command, &locArgc, pArgs);
        CharLower (argstr [0]);  /* The command is case-insensitive */

        if (debug) _tprintf (_T("\n%s %s %s %s"), argstr[0], argstr[1],
                                 argstr[2], argstr[3]);

        if (_tcscmp (argstr[0], _T("create")) == 0)
        {
            Create (locArgc, pArgs, command);
        }
        else if (_tcscmp (argstr[0], _T("delete")) == 0)
        {
            Delete (locArgc, pArgs, command);
        }
        else if (_tcscmp (argstr[0], _T("start")) == 0)
        {
            Start (locArgc, pArgs, command);
        }
        else if (_tcscmp (argstr[0], _T("control")) == 0)
        {
            Control (locArgc, pArgs, command);
        }
        else if (_tcscmp (argstr[0], _T("quit")) == 0)
        {
            exitFlag = TRUE;
        }
        else _tprintf (_T("\nCommand not recognized"));
    }

    CloseServiceHandle (hScm);
    return 0;
}
Пример #3
0
_tmain (int argc, LPTSTR argv [])
{
	/* MAX_CLIENTS is defined in ClientServer.h. */
	/* Currently limited to MAXIMUM_WAIT_OBJECTS WaitForMultipleObjects */
	/* is used by the main thread to wait for the server threads */

	HANDLE hNp, hMonitor, hSrvrThread [MAX_CLIENTS], hSecHeap = NULL;
	DWORD iNp, MonitorId, ThreadId;
	DWORD AceMasks [] =	/* Named pipe access rights - Only clients
		* run by the owner will be able to connect. */
		{FILE_GENERIC_READ | FILE_GENERIC_WRITE, 0, 0 };
	LPSECURITY_ATTRIBUTES pNPSA = NULL;
	THREAD_ARG ThArgs [MAX_CLIENTS];

	if (!WindowsVersionOK (3, 1)) 
		ReportError (_T("This program requires Windows NT 3.1 or greater"), 1, FALSE);

	/* Console control handler to permit server shutdown */
	if (!SetConsoleCtrlHandler (Handler, TRUE))
		ReportError (_T("Cannot create Ctrl handler"), 1, TRUE);

	
	if (argc == 4)		/* Optional pipe security. */
		pNPSA = InitializeAccessOnlySA (0440, argv [1], argv [2], AceMasks, &hSecHeap);
			
	/* Create a thread broadcast pipe name periodically. */
	hMonitor = (HANDLE) _beginthreadex (NULL, 0, ServerBroadcast, NULL, 0, &MonitorId);

	/*	Create a pipe instance for every server thread.
	 *	Create a temp file name for each thread.
	 *	Create a thread to service that pipe. */

	for (iNp = 0; iNp < MAX_CLIENTS; iNp++) {
		hNp = CreateNamedPipe ( SERVER_PIPE, PIPE_ACCESS_DUPLEX,
				PIPE_READMODE_MESSAGE | PIPE_TYPE_MESSAGE | PIPE_WAIT,
				MAX_CLIENTS, 0, 0, INFINITE, pNPSA);

		if (hNp == INVALID_HANDLE_VALUE)
			ReportError (_T ("Failure to open named pipe."), 1, TRUE);
		ThArgs [iNp].hNamedPipe = hNp;
		ThArgs [iNp].ThreadNo = iNp;
		GetTempFileName (_T ("."), _T ("CLP"), 0, ThArgs [iNp].TmpFileName);
		hSrvrThread [iNp] = (HANDLE)_beginthreadex (NULL, 0, Server,
				&ThArgs [iNp], 0, &ThreadId);
		if (hSrvrThread [iNp] == NULL)
			ReportError (_T ("Failure to create server thread."), 2, TRUE);
	}
	
	/* Wait for all the threads to terminate. */

	WaitForMultipleObjects (MAX_CLIENTS, hSrvrThread, TRUE, INFINITE);
	_tprintf (_T("All Server worker threads have shut down.\n"));

	WaitForSingleObject (hMonitor, INFINITE);
	_tprintf (_T("Monitor thread has shut down.\n"));

	CloseHandle (hMonitor);
	for (iNp = 0; iNp < MAX_CLIENTS; iNp++) { 
		/* Close pipe handles and delete temp files */
		/* Closing temp files is redundant, as the worker threads do it */
		CloseHandle (hSrvrThread [iNp]);
		DeleteFile (ThArgs [iNp].TmpFileName);
	}
	if (hSecHeap != NULL) HeapDestroy (hSecHeap);
	_tprintf (_T("Server process will exit.\n"));
	/*	ExitProcess assures a clean exit. All DLL entry points will be 
		called, indicating process detach. Among other reasons that this is
		important is that connection threads may still be blocked on
		ConnectNamedPipe calls. */
	ExitProcess (0);

	return 0;
}
Пример #4
0
int main (int argc, char * argv[])
{
	DWORD nchar = 0, nword = 0, nline = 0;
    PTP_WORK *pWorkObjects;
    WORK_OBJECT_ARG ** pWorkObjArgsArray, *pObjectArg;
	TP_CALLBACK_ENVIRON cbe;  // Callback environment
	int nThread, iThrd;
	
    if (!WindowsVersionOK (6, 0)) 
        ReportError ("This program requires Windows NT 6.0 or greater", 1, TRUE);

	if (argc < 2) {
		printf ("Usage: wcMT_vtp filename ... filename\n");
		return 1;
	}

	/* Create a worker thread for each file on the command line */
	nThread = (DWORD)argc - 1;
    pWorkObjects = malloc (nThread * sizeof(PTP_WORK));
	if (pWorkObjects != NULL)
		pWorkObjArgsArray = malloc (nThread * sizeof(WORK_OBJECT_ARG *));
	if (pWorkObjects == NULL || pWorkObjArgsArray == NULL)
        ReportError ("Cannot allocate working memory for worke item or argument array.", 2, TRUE);

	InitializeThreadpoolEnvironment (&cbe);

	/* Create a work object argument for each file on the command line.
	   First put the file names in the thread arguments.	*/
	for (iThrd = 0; iThrd < nThread; iThrd++) {
		pObjectArg = (pWorkObjArgsArray[iThrd] = _aligned_malloc (sizeof(WORK_OBJECT_ARG), CACHE_LINE_SIZE));
		if (NULL == pObjectArg)
			ReportError ("Cannot allocate memory for a thread argument structure.", 3, TRUE);
		pObjectArg->filename = argv[iThrd+1];
		pObjectArg->kword = pObjectArg->kchar = pObjectArg->kline = 0;
		pWorkObjects[iThrd] = CreateThreadpoolWork (wcfunc, pObjectArg, &cbe);
        if (pWorkObjects[iThrd] == NULL) 
            ReportError ("Cannot create consumer thread", 4, TRUE);
		SubmitThreadpoolWork (pWorkObjects[iThrd]);
	}
	
	/* Worker objects are all submitted. Wait for them 	*/
	/* to complete and accumulate the results			*/
	for (iThrd = 0; iThrd < nThread; iThrd++) {
		/* Wait for the thread pool work item to complete */
		WaitForThreadpoolWorkCallbacks (pWorkObjects[iThrd], FALSE);
		CloseThreadpoolWork(pWorkObjects[iThrd]);
	}
    free (pWorkObjects);
	
	/* Accumulate the results							*/
	for (iThrd = 0; iThrd < argc - 1; iThrd++) {
		pObjectArg = pWorkObjArgsArray[iThrd]; 
		nchar += pObjectArg->kchar;
		nword += pObjectArg->kword;
		nline += pObjectArg->kline;
		printf ("%10d %9d %9d %s\n", pObjectArg->kline,
			pObjectArg->kword, pObjectArg->kchar,
			pObjectArg->filename);
	}
	free (pWorkObjArgsArray);
	printf ("%10d %9d %9d \n", nline, nword, nchar);
	return 0;
}