cmpp.cpp

来自「vc开发的一个cmpp(中国移动点对点通讯)通讯程序」· C++ 代码 · 共 126 行

CPP
126
字号
// cmpp.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "cmpp.h"
#include "service.h"
#include <winsvc.h>
#include "DeliverThread.h"
#include "ServerThread.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       CMPP_INI_FILE[100];
extern char WEIMA[100];
extern char WEIMANEW[100];
CServerThread g_stServerThread;
CDeliverThread g_stDeliverThread;

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
    //
    ////////////////////////////////////////////////////////
	LoadIni();

	g_stDeliverThread.InitInstance();

	Sleep(2000);
	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()
{
	g_stDeliverThread.g_bDeliverThreadExit = true;
	g_stServerThread.g_bServerThreadExit = true;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?