mirror of
https://github.com/yuanyuanxiang/SimpleRemoter.git
synced 2026-01-23 07:43:13 +08:00
Feature: Support client running as windows service
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
#include <shellapi.h>
|
||||
#include <corecrt_io.h>
|
||||
#include "domain_pool.h"
|
||||
#include "ClientApp.h"
|
||||
|
||||
BOOL IsProcessExit();
|
||||
|
||||
@@ -22,8 +23,11 @@ BOOL IsSharedRunning(void* thisApp);
|
||||
|
||||
BOOL IsClientAppRunning(void* thisApp);
|
||||
|
||||
DWORD WINAPI StartClientApp(LPVOID param);
|
||||
|
||||
// <20>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD>ࣺ<EFBFBD><E0A3BA>ȫ<EFBFBD>ֱ<EFBFBD><D6B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>.
|
||||
typedef struct ClientApp {
|
||||
class ClientApp : public App {
|
||||
public:
|
||||
State g_bExit; // Ӧ<>ó<EFBFBD><C3B3><EFBFBD>״̬<D7B4><CCAC>1-<2D><><EFBFBD>ض<EFBFBD><D8B6>˳<EFBFBD> 2-<2D><><EFBFBD>ض<EFBFBD><D8B6>˳<EFBFBD> 3-<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
BOOL g_bThreadExit; // <20><><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD>״̬
|
||||
HINSTANCE g_hInstance; // <20><><EFBFBD>̾<EFBFBD><CCBE><EFBFBD>
|
||||
@@ -36,10 +40,14 @@ typedef struct ClientApp {
|
||||
static CLock m_Locker;
|
||||
ClientApp(CONNECT_ADDRESS*conn, IsRunning run, BOOL shared=FALSE)
|
||||
{
|
||||
memset(this, 0, sizeof(ClientApp));
|
||||
g_bExit = S_CLIENT_NORMAL;
|
||||
g_bThreadExit = FALSE;
|
||||
g_hInstance = NULL;
|
||||
g_Connection = new CONNECT_ADDRESS(*conn);
|
||||
g_hEvent = NULL;
|
||||
m_bIsRunning = run;
|
||||
m_bShared = shared;
|
||||
m_ID = 0;
|
||||
g_bThreadExit = TRUE;
|
||||
}
|
||||
std::vector<std::string> GetSharedMasterList()
|
||||
@@ -94,7 +102,26 @@ typedef struct ClientApp {
|
||||
g_bExit = state;
|
||||
m_Locker.Unlock();
|
||||
}
|
||||
} ClientApp;
|
||||
virtual bool Initialize() override {
|
||||
g_Connection->SetType(CLIENT_TYPE_ONE);
|
||||
return true;
|
||||
}
|
||||
virtual bool Start(bool block) override {
|
||||
if (block) StartClientApp(this);
|
||||
else CloseHandle(__CreateThread(0, 0, StartClientApp, this, 0, 0));
|
||||
return true;
|
||||
}
|
||||
virtual bool Stop() override {
|
||||
g_bExit = S_CLIENT_EXIT;
|
||||
return true;
|
||||
}
|
||||
bool Run(bool block = true) {
|
||||
if (!Initialize()) return false;
|
||||
if (!Start(block)) return false;
|
||||
if (block) Stop();
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
ClientApp* NewClientStartArg(const char* remoteAddr, IsRunning run = IsClientAppRunning, BOOL shared=FALSE);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user