📄 sgip.cpp
字号:
// SGip.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <winsvc.h>
#include <process.h>
#include <tchar.h>
#include "service.h"
#include "server.h"
#include "deliverThread.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// The one and only application object
CWinApp theApp;
using namespace std;
extern char SGIP_INI_FILE[100];
HANDLE hServerStopEvent = NULL;
CServerThread g_stServerThread;
CDeliverThread g_stDeliverThread;
extern BOOL g_bExit;
extern BOOL g_bDeliverThreadExit;
//
// FUNCTION: ServiceStart
//
// PURPOSE: Actual code of the service
// that does the work.
//
// PARAMETERS:
// dwArgc - number of command line arguments
// lpszArgv - array of command line arguments
//
// RETURN VALUE:
// none
//
// COMMENTS:
// The default behavior is to open a
// named pipe, \\.\pipe\simple, and read
// from it. It the modifies the data and
// writes it back to the pipe. The service
// stops when hServerStopEvent is signalled
//
VOID ServiceStart (DWORD dwArgc, LPTSTR *lpszArgv)
{
///////////////////////////////////////////////////
//
// Service initialization
//
// report the status to the service control manager.
//
if (!ReportStatusToSCMgr(
SERVICE_START_PENDING, // service state
NO_ERROR, // exit code
3000)) // wait hint
goto cleanup;
// report the status to the service control manager.
//
if (!ReportStatusToSCMgr(
SERVICE_START_PENDING, // service state
NO_ERROR, // exit code
3000)) // wait hint
goto cleanup;
// report the status to the service control manager.
//
if (!ReportStatusToSCMgr(
SERVICE_START_PENDING, // service state
NO_ERROR, // exit code
3000)) // wait hint
goto cleanup;
// report the status to the service control manager.
//
if (!ReportStatusToSCMgr(
SERVICE_START_PENDING, // service state
NO_ERROR, // exit code
3000)) // wait hint
goto cleanup;
if (!AfxSocketInit())
goto cleanup;
// report the status to the service control manager.
//
if (!ReportStatusToSCMgr(
SERVICE_RUNNING, // service state
NO_ERROR, // exit code
0)) // wait hint
goto cleanup;
//
// End of initialization
//
////////////////////////////////////////////////////////
if(GetPrivateProfileInt("系统","关闭MO",0,SGIP_INI_FILE)==0)
{
g_stDeliverThread.InitInstance();
}
if(GetPrivateProfileInt("系统","关闭MT",0,SGIP_INI_FILE)==0)
{
g_stServerThread.InitInstance();
g_stServerThread.Run();
}
////////////////////////////////////////////////////////
//
// Service is now running, perform work until shutdown
//
// g_stTransFile.StartTransFile();
cleanup:
return;
}
//
// FUNCTION: ServiceStop
//
// PURPOSE: Stops the service
//
// PARAMETERS:
// none
//
// RETURN VALUE:
// none
//
// COMMENTS:
// If a ServiceStop procedure is going to
// take longer than 3 seconds to execute,
// it should spawn a thread to execute the
// stop code, and return. Otherwise, the
// ServiceControlManager will believe that
// the service has stopped responding.
//
VOID ServiceStop()
{
if ( hServerStopEvent )
SetEvent(hServerStopEvent);
g_bDeliverThreadExit = true;
Sleep(500);
g_bExit = true;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -