使用soui开发的mbc,只支持windows版本
w1146869587
2022-01-24 479b1995ef435713c2cf4f0da8de3a6af6c30922
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// OIMOBOXWatchDirService.cpp : implementation file
//
 
#include "stdafx.h"
#include "OIMOBOXWatchDir.h"
#include "OIMOBOXWatchDirService.h"
 
COIMOBOXWatchDirService::COIMOBOXWatchDirService(): CNTService( _T( "OIMOBOXWatchDir" ),            // ·þÎñÃû³Æ
                                   _T( "OpenInfo MOBOX BackupDir Service" ),            // ·þÎñÏÔʾÃû³Æ
                                   SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_PAUSE_CONTINUE,
                                   _T( "OpenInfo MOBOX ±¸·Ý¼àÊÓ·þÎñ" ) )      // ·þÎñÃèÊö
{
    ::CoInitialize( NULL );
    m_hSvcStopEvent = NULL;
    m_hSvcThread = NULL;
    m_pMOBOXWatchDirDlg = NULL;
}
 
COIMOBOXWatchDirService::~COIMOBOXWatchDirService()
{
    ::CoUninitialize();
        m_EventLogSource.Report( EVENTLOG_INFORMATION_TYPE, MSG_SERVICE_INFO, _T( "~COIMOBOXWatchDirService¡£" ) );
}
 
 
// COIMOBOXWatchDirService member functions
void COIMOBOXWatchDirService::ServiceMain( DWORD /*dwArgc*/, LPTSTR* /*lpszArgv*/ )
{
    // register our control handler
    RegisterCtrlHandler();
 
    // Pretend that starting up takes some time
    ReportStatusToSCM( SERVICE_START_PENDING, NO_ERROR, 0, 1, 0 );
        // ´´½¨·þÎñֹͣʼþ
    m_hSvcStopEvent        = CreateEvent( NULL, TRUE, FALSE, NULL );
    if( NULL == m_hSvcStopEvent )
    {
        
        Report( _T("´´½¨·þÎñֹͣʼþʧ°Ü"), EVENTLOG_ERROR_TYPE );
        ReportStatusToSCM( SERVICE_STOPPED, NO_ERROR, 0, 1, 0 );
        return;
    }
    if ( !Start() )
    {
        Report( _T("³õʼ»¯Ê§°Ü"), EVENTLOG_ERROR_TYPE );
        ReportStatusToSCM( SERVICE_STOPPED, NO_ERROR, 0, 1, 0 );
        return;
    }
    // ´´½¨·þÎñÏß³Ì
    /*m_hSvcThread = (HANDLE)_beginthreadex( NULL, 0, &ServiceThread, (LPVOID)this, 0, NULL );
    if( NULL == m_hSvcThread )
    {
        Report( _T("´´½¨·þÎñÏß³Ìʧ°Ü"), EVENTLOG_ERROR_TYPE );
        ReportStatusToSCM( SERVICE_STOPPED, ERROR, 0, 1, 0 );
        return;
    }
    CloseHandle( m_hSvcThread );*/
    Report( _T("MOBOXWatchDirService start") );
    ReportStatusToSCM( SERVICE_RUNNING, NO_ERROR, 0, 1, 0 );
    /*while( 1 )
    {
        WaitForSingleObject( m_hSvcStopEvent, INFINITE );
        Report( _T("MOBOXWatchDirService end") );
        ReportStatusToSCM( SERVICE_STOPPED, NO_ERROR, 0, 1, 0 );
        return;
    }*/
}
BOOL COIMOBOXWatchDirService::Start()
{
    CString        strError;
    CString    strLog;
    Report(_T( "³õʼ»¯·þÎñÐÅÏ¢¡£" ) );
    if(m_pMOBOXWatchDirDlg)
    {
        if( ::IsWindow(m_pMOBOXWatchDirDlg->GetSafeHwnd()))
            m_pMOBOXWatchDirDlg->DestroyWindow();
        delete m_pMOBOXWatchDirDlg;
        m_pMOBOXWatchDirDlg = NULL;
        Report( _T( " Start 1" ) );
    }
    m_pMOBOXWatchDirDlg = new COIMOBOXWatchDirDlg;
    m_pMOBOXWatchDirDlg->m_hSvcStopEvent = m_hSvcStopEvent;
    if ( !m_pMOBOXWatchDirDlg->Create( IDD_OIMOBOXWATCHDIR_DIALOG,m_pMOBOXWatchDirDlg ) )
    {
        delete m_pMOBOXWatchDirDlg;
        m_pMOBOXWatchDirDlg = NULL;
        SetEvent( m_hSvcStopEvent );
        strError = _T( "³õʼ»¯·þÎñÐÅϢʧ°Ü¡£" );
        Report( strError,EVENTLOG_ERROR_TYPE, MSG_SERVICE_INFO  );
        ReportStatusToSCM( SERVICE_STOPPED, ERROR, 0, 1, 0 );
        return FALSE;
    }
    //#ifndef _DEBUG
    //    m_pMOBOXWatchDirDlg->ShowWindow( SW_HIDE );
    //#else
        m_pMOBOXWatchDirDlg->ShowWindow( SW_SHOW );
    //#endif
    AfxGetApp()->m_pMainWnd = m_pMOBOXWatchDirDlg;
    Report( _T( "³õʼ»¯·þÎñÐÅÏ¢³É¹¦¡£" ) );
    // Report to the event log that the service has started successfully
    Report(m_sDisplayName, EVENTLOG_INFORMATION_TYPE, CNTS_MSG_SERVICE_STARTED  );
    ReportStatusToSCM( SERVICE_RUNNING, NO_ERROR, 0, 1, 0 );
//    pool.WaitForShutdownToComplete( 15000, true );
    return TRUE;
}
 
void COIMOBOXWatchDirService::OnStop()
{
    Report( _T("OnStop") );
    /*if(m_pMOBOXWatchDirDlg)
    {
        if( ::IsWindow(m_pMOBOXWatchDirDlg->GetSafeHwnd()))
            m_pMOBOXWatchDirDlg->DestroyWindow();
        delete m_pMOBOXWatchDirDlg;
        m_pMOBOXWatchDirDlg = NULL;
        Report( _T( " OnStop 2" ) );
    }*/
    SetEvent( m_hSvcStopEvent );
    // Report to the event log that the service has stopped successfully
    Report( m_sDisplayName,EVENTLOG_INFORMATION_TYPE, CNTS_MSG_SERVICE_STOPPED  );
}
 
void COIMOBOXWatchDirService::OnPause()
{
    ReportStatusToSCM( SERVICE_PAUSED, ERROR, 0, 1, 0 );
    // Report to the event log that the service has paused successfully
    Report(m_sDisplayName, EVENTLOG_INFORMATION_TYPE, CNTS_MSG_SERVICE_PAUSED );
}
 
void COIMOBOXWatchDirService::OnContinue()
{
    ReportStatusToSCM( SERVICE_RUNNING, ERROR, 0, 1, 0 );
    Report( m_sDisplayName, EVENTLOG_INFORMATION_TYPE, CNTS_MSG_SERVICE_CONTINUED );
    // Report to the event log that the service has continued continued
    
}
 
 
void COIMOBOXWatchDirService::Report( LPCTSTR lpszString, WORD wType/*=EVENTLOG_INFORMATION_TYPE*/ ,
                            DWORD dwEventID/*=MSG_SERVICE_INFO*/ )
{
    m_EventLogSource.Report( wType, dwEventID, lpszString );
}