Ejemplo n.º 1
0
//////////////////////////////////////////////////////////////////////
//
// This routine gets used to start your service
//
VOID WINAPI CodeXLDriversLoadServiceMain(DWORD dwArgc, LPTSTR* lpszArgv)
{
    (void)(lpszArgv);
    (void)(dwArgc);

    serviceStatus.dwServiceType        = SERVICE_WIN32;
    serviceStatus.dwCurrentState       = SERVICE_START_PENDING;
    serviceStatus.dwControlsAccepted   = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN | SERVICE_ACCEPT_PAUSE_CONTINUE;
    serviceStatus.dwWin32ExitCode      = 0;
    serviceStatus.dwServiceSpecificExitCode = 0;
    serviceStatus.dwCheckPoint         = 0;
    serviceStatus.dwWaitHint           = 0;

    hServiceStatusHandle = RegisterServiceCtrlHandler(pServiceName, CodeXLDriversLoadServiceHandler);

    if (hServiceStatusHandle == 0)
    {
        WriteErrorLog(L"RegisterServiceCtrlHandler failed");
        return;
    }

    // Initialization complete - report running status
    serviceStatus.dwCurrentState       = SERVICE_RUNNING;
    serviceStatus.dwCheckPoint         = 0;
    serviceStatus.dwWaitHint           = 0;

    if (!SetServiceStatus(hServiceStatusHandle, &serviceStatus))
    {
        WriteErrorLog(L"SetServiceStatus failed");
    }
}
Ejemplo n.º 2
0
int test_outputfunc()
{
	LOG		*g = NULL ;
	
	g = CreateLogHandle() ;
	if( g == NULL )
	{
		printf( "创建日志句柄失败errno[%d]\n" , errno );
		return -1;
	}
	else
	{
		printf( "创建日志句柄成功\n" );
	}
	
	SetLogOutput( g , LOG_OUTPUT_CALLBACK , "127.0.0.1:514" , & MyOpenLogFirst , NULL , & MyWriteLog , NULL , NULL , & MyCloseLogFinally );
	SetLogLevel( g , LOG_LEVEL_INFO );
	SetLogStyles( g , LOG_STYLES_LOG , LOG_NO_STYLEFUNC );
	
	WriteDebugLog( g , __FILE__ , __LINE__ , "hello iLOG3\n" );
	WriteInfoLog( g , __FILE__ , __LINE__ , "hello iLOG3\n" );
	WriteWarnLog( g , __FILE__ , __LINE__ , "hello iLOG3\n" );
	WriteErrorLog( g , __FILE__ , __LINE__ , "hello iLOG3\n" );
	WriteFatalLog( g , __FILE__ , __LINE__ , "hello iLOG3\n" );
	
	DestroyLogHandle( g );
	printf( "销毁日志句柄\n" );
	
	return 0;
}
Ejemplo n.º 3
0
BOOL StopService(wchar_t* pName)
{
    // stop service with given name
    SC_HANDLE schSCManager = OpenSCManager(nullptr, nullptr, SC_MANAGER_ALL_ACCESS);

    if (schSCManager == 0)
    {
        WriteErrorLog(L"OpenSCManager failed");
    }
    else
    {
        // open the service
        SC_HANDLE schService = OpenService(schSCManager, pName, SERVICE_ALL_ACCESS);

        if (schService == 0)
        {
            WriteErrorLog(L"OpenService failed");
        }
        else
        {
            // call ControlService to stop the given service
            SERVICE_STATUS status;

            if (ControlService(schService, SERVICE_CONTROL_STOP, &status))
            {
                CloseServiceHandle(schService);
                CloseServiceHandle(schSCManager);
                return TRUE;
            }
            else
            {
                WriteErrorLog(L"ControlService failed");
            }

            CloseServiceHandle(schService);
        }

        CloseServiceHandle(schSCManager);
    }

    return FALSE;
}
Ejemplo n.º 4
0
BOOL StartService(wchar_t* pName, int nArg, wchar_t** pArg)
{
    // start service with given name
    SC_HANDLE schSCManager = OpenSCManager(nullptr, nullptr, SC_MANAGER_ALL_ACCESS);

    if (schSCManager == 0)
    {
        WriteErrorLog(L"OpenSCManager failed");
    }
    else
    {
        // open the service
        SC_HANDLE schService = OpenService(schSCManager, pName, SERVICE_ALL_ACCESS);

        if (schService == 0)
        {
            WriteErrorLog(L"OpenService failed");
        }
        else
        {
            // Start The Service
            if (StartService(schService, nArg, (const wchar_t**)pArg))
            {
                CloseServiceHandle(schService);
                CloseServiceHandle(schSCManager);
                return TRUE;
            }
            else
            {
                WriteErrorLog(L"StartService failed");
            }

            CloseServiceHandle(schService);
        }

        CloseServiceHandle(schSCManager);
    }

    return FALSE;
}
Ejemplo n.º 5
0
dword OptionsMenu_HandleKey( dword key, dword keyHW )
{
	if ( windowActive )
	{
		int selection = TAP_Win_GetSelection( &window );

		switch ( key )
		{
		case RKEY_Ok:
			if ( selection == optionCount )
			{
				WriteErrorLog();
				OptionsMenu_Close();
			}
			if ( selection == optionCount+2 )
			{
				// Cancel - Reload original settings
				OptionsMenu_Close();
				Settings_Load();
			}
			return 0;

		case RKEY_0:
			if ( selection == optionCount+1 )
			{
				// Reset to defaults
				Settings_Reset();
				OptionsMenu_UpdateText();
			}
			return 0;

		case RKEY_Exit:
			OptionsMenu_Close();
			Settings_Save();
			return 0;

		case RKEY_VolUp:
			if ( selection == 0 )
				settings.insertSpace = !settings.insertSpace;
			else if ( selection == 1 )
				settings.addGenre = !settings.addGenre;
			OptionsMenu_UpdateText();
			return 0;

		case RKEY_VolDown:
			if ( selection == 0 )
				settings.insertSpace = !settings.insertSpace;
			else if ( selection == 1 )
				settings.addGenre = !settings.addGenre;
			OptionsMenu_UpdateText();
			return 0;

		case RKEY_ChDown:
			if ( selection < optionCount+2 )
			{
				TAP_Win_Action( &window, key );
				OptionsMenu_UpdateText();
			}
			return 0;
		case RKEY_ChUp:
			if ( selection > 0 )
			{
				TAP_Win_Action( &window, key );
				OptionsMenu_UpdateText();
			}
			return 0;

		default:
			TAP_Win_Action( &window, key ); // send all other key's to menu-Win
			return 0;
		}
	}

	return key;
}
Ejemplo n.º 6
0
void main(int argc, char* argv[])
{
    // error message
    wchar_t pTemp[121];
    unsigned int errStrSize = 120;

    // initialize global critical section
    ::InitializeCriticalSection(&gCS);

    // initialize variables for .exe, .ini, and .log file names
    wchar_t pModuleFile[nBufferSize + 1];
    DWORD dwSize = GetModuleFileName(nullptr, (LPTSTR)pModuleFile, nBufferSize);
    pModuleFile[dwSize] = 0;

    if (dwSize > 4 && pModuleFile[dwSize - 4] == '.')
    {
        swprintf(pExeFile, nBufferSize, L"%s", pModuleFile);
        pModuleFile[dwSize - 4] = 0;
        swprintf(pLogFile, nBufferSize, L"%s.log", pModuleFile);
    }
    else
    {
        printf("Invalid module file name: %ws\r\n", pModuleFile);
        return;
    }

    WriteLog(pExeFile);
    WriteLog(pLogFile);
    wcscpy_s(pServiceName, 500, L"CodeXLDriversLoadService");
    WriteLog(pServiceName);

    // uninstall service if switch is "-u"
    if (argc == 2 && _stricmp("-uninstall", argv[1]) == 0)
    {
        UnInstall(pServiceName);
    }
    // install service if switch is "-i"
    else if (argc == 2 && _stricmp("-install", argv[1]) == 0)
    {
        Install(pExeFile, pServiceName);
    }
    // stop a service with given name
    else if (argc == 2 && _stricmp("-stop", argv[1]) == 0)
    {
        if (StopService(pServiceName))
        {
            swprintf(pTemp, errStrSize, L"Stopped service %s", pServiceName);
            WriteLog(pTemp);
        }
        else
        {
            swprintf(pTemp, errStrSize, L"Failed to stop service %s", pServiceName);
            WriteLog(pTemp);
        }
    }
    // run a service with given name
    else if (argc == 2 && _stricmp("-start", argv[1]) == 0)
    {
        WriteLog(L"StartService");

        if (StartService(pServiceName, 0, nullptr))
        {
            swprintf(pTemp, errStrSize, L"Ran service %s", pServiceName);
            WriteLog(pTemp);
        }
        else
        {
            swprintf(pTemp, errStrSize, L"Failed to run service %s", pServiceName);
            WriteLog(pTemp);
        }
    }
    // assume user is starting this service
    else
    {
        // start a worker thread to load driver
        if (_beginthread(WorkerProc, 0, nullptr) == -1)
        {
            WriteErrorLog(L"_beginthread failed");
        }

        // pass dispatch table to service controller
        if (!StartServiceCtrlDispatcher(DispatchTable))
        {
            WriteErrorLog(L"StartServiceCtrlDispatcher failed");
        }

        // you don't get here unless the service is shutdown
    }

    ::DeleteCriticalSection(&gCS);
}