2025-11-29 14:13:34 +01:00
|
|
|
|
|
2025-11-23 18:13:39 +01:00
|
|
|
|
// 2015Remote.cpp : 定义应用程序的类行为。
|
2019-01-05 20:21:43 +08:00
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
#include "stdafx.h"
|
|
|
|
|
|
#include "2015Remote.h"
|
2025-11-29 14:13:34 +01:00
|
|
|
|
#include "SplashDlg.h"
|
2019-01-05 20:21:43 +08:00
|
|
|
|
#include "2015RemoteDlg.h"
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef _DEBUG
|
|
|
|
|
|
#define new DEBUG_NEW
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
2025-11-23 18:13:39 +01:00
|
|
|
|
// dump相关
|
2019-01-10 19:35:03 +08:00
|
|
|
|
#include <io.h>
|
|
|
|
|
|
#include <direct.h>
|
|
|
|
|
|
#include <DbgHelp.h>
|
2025-06-29 21:25:59 +08:00
|
|
|
|
#include "IOCPUDPServer.h"
|
2025-11-23 18:13:39 +01:00
|
|
|
|
#include "ServerServiceWrapper.h"
|
2019-01-10 19:35:03 +08:00
|
|
|
|
#pragma comment(lib, "Dbghelp.lib")
|
|
|
|
|
|
|
2025-12-02 21:45:43 +01:00
|
|
|
|
BOOL ServerPair::StartServer(pfnNotifyProc NotifyProc, pfnOfflineProc OffProc, USHORT uPort)
|
|
|
|
|
|
{
|
|
|
|
|
|
UINT ret1 = m_tcpServer->StartServer(NotifyProc, OffProc, uPort);
|
|
|
|
|
|
if (ret1) THIS_APP->MessageBox(CString("启动TCP服务失败: ") + std::to_string(uPort).c_str()
|
2025-12-05 17:40:12 +01:00
|
|
|
|
+ CString("。错误码: ") + std::to_string(ret1).c_str(), "提示", MB_ICONINFORMATION);
|
2025-12-02 21:45:43 +01:00
|
|
|
|
UINT ret2 = m_udpServer->StartServer(NotifyProc, OffProc, uPort);
|
|
|
|
|
|
if (ret2) THIS_APP->MessageBox(CString("启动UDP服务失败: ") + std::to_string(uPort).c_str()
|
2025-12-05 17:40:12 +01:00
|
|
|
|
+ CString("。错误码: ") + std::to_string(ret2).c_str(), "提示", MB_ICONINFORMATION);
|
2025-12-02 21:45:43 +01:00
|
|
|
|
return (ret1 == 0 || ret2 == 0);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-15 04:32:59 +08:00
|
|
|
|
CMy2015RemoteApp* GetThisApp()
|
|
|
|
|
|
{
|
|
|
|
|
|
return ((CMy2015RemoteApp*)AfxGetApp());
|
2025-06-18 04:22:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-15 04:32:59 +08:00
|
|
|
|
config& GetThisCfg()
|
|
|
|
|
|
{
|
|
|
|
|
|
config *cfg = GetThisApp()->GetCfg();
|
|
|
|
|
|
return *cfg;
|
2025-06-18 04:22:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-15 04:32:59 +08:00
|
|
|
|
std::string GetMasterHash()
|
|
|
|
|
|
{
|
|
|
|
|
|
static std::string hash(skCrypt(MASTER_HASH));
|
|
|
|
|
|
return hash;
|
2025-07-13 04:37:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-15 04:32:59 +08:00
|
|
|
|
/**
|
2025-11-23 18:13:39 +01:00
|
|
|
|
* @brief 程序遇到未知BUG导致终止时调用此函数,不弹框
|
|
|
|
|
|
* 并且转储dump文件到dump目录.
|
2019-01-10 19:35:03 +08:00
|
|
|
|
*/
|
|
|
|
|
|
long WINAPI whenbuged(_EXCEPTION_POINTERS *excp)
|
|
|
|
|
|
{
|
2025-11-23 18:13:39 +01:00
|
|
|
|
// 获取dump文件夹,若不存在,则创建之
|
|
|
|
|
|
char dumpDir[_MAX_PATH];
|
|
|
|
|
|
char dumpFile[_MAX_PATH + 64];
|
|
|
|
|
|
|
|
|
|
|
|
if (!GetModuleFileNameA(NULL, dumpDir, _MAX_PATH)) {
|
|
|
|
|
|
return EXCEPTION_EXECUTE_HANDLER;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
char* p = strrchr(dumpDir, '\\');
|
|
|
|
|
|
if (p) {
|
|
|
|
|
|
strcpy_s(p + 1, _MAX_PATH - (p - dumpDir + 1), "dump");
|
|
|
|
|
|
} else {
|
|
|
|
|
|
strcpy_s(dumpDir, _MAX_PATH, "dump");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (_access(dumpDir, 0) == -1)
|
|
|
|
|
|
_mkdir(dumpDir);
|
|
|
|
|
|
|
|
|
|
|
|
// 构建完整的dump文件路径
|
|
|
|
|
|
char curTime[64];
|
|
|
|
|
|
time_t TIME = time(0);
|
|
|
|
|
|
struct tm localTime;
|
|
|
|
|
|
localtime_s(&localTime, &TIME);
|
|
|
|
|
|
strftime(curTime, sizeof(curTime), "\\YAMA_%Y-%m-%d %H%M%S.dmp", &localTime);
|
|
|
|
|
|
sprintf_s(dumpFile, sizeof(dumpFile), "%s%s", dumpDir, curTime);
|
|
|
|
|
|
|
|
|
|
|
|
HANDLE hFile = ::CreateFileA(dumpFile, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
|
2025-10-15 04:32:59 +08:00
|
|
|
|
FILE_ATTRIBUTE_NORMAL, NULL);
|
|
|
|
|
|
if(INVALID_HANDLE_VALUE != hFile) {
|
|
|
|
|
|
MINIDUMP_EXCEPTION_INFORMATION einfo = {::GetCurrentThreadId(), excp, FALSE};
|
|
|
|
|
|
::MiniDumpWriteDump(::GetCurrentProcess(), ::GetCurrentProcessId(),
|
|
|
|
|
|
hFile, MiniDumpWithFullMemory, &einfo, NULL, NULL);
|
|
|
|
|
|
::CloseHandle(hFile);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return EXCEPTION_EXECUTE_HANDLER;
|
2019-01-10 19:35:03 +08:00
|
|
|
|
}
|
2019-01-05 20:21:43 +08:00
|
|
|
|
|
|
|
|
|
|
// CMy2015RemoteApp
|
|
|
|
|
|
|
|
|
|
|
|
BEGIN_MESSAGE_MAP(CMy2015RemoteApp, CWinApp)
|
2025-10-15 04:32:59 +08:00
|
|
|
|
ON_COMMAND(ID_HELP, &CWinApp::OnHelp)
|
2019-01-05 20:21:43 +08:00
|
|
|
|
END_MESSAGE_MAP()
|
|
|
|
|
|
|
2025-06-18 04:22:48 +08:00
|
|
|
|
std::string GetPwdHash();
|
2019-01-05 20:21:43 +08:00
|
|
|
|
|
2025-11-23 18:13:39 +01:00
|
|
|
|
// CMy2015RemoteApp 构造
|
2019-01-05 20:21:43 +08:00
|
|
|
|
|
|
|
|
|
|
CMy2015RemoteApp::CMy2015RemoteApp()
|
|
|
|
|
|
{
|
2025-11-23 18:13:39 +01:00
|
|
|
|
// 支持重新启动管理器
|
2025-10-15 04:32:59 +08:00
|
|
|
|
m_dwRestartManagerSupportFlags = AFX_RESTART_MANAGER_SUPPORT_RESTART;
|
2019-01-05 20:21:43 +08:00
|
|
|
|
|
2025-11-23 18:13:39 +01:00
|
|
|
|
// TODO: 在此处添加构造代码,
|
|
|
|
|
|
// 将所有重要的初始化放置在 InitInstance 中
|
2025-10-15 04:32:59 +08:00
|
|
|
|
m_Mutex = NULL;
|
2025-07-27 21:56:52 +08:00
|
|
|
|
#ifdef _DEBUG
|
2025-10-15 04:32:59 +08:00
|
|
|
|
std::string masterHash(GetMasterHash());
|
|
|
|
|
|
m_iniFile = GetPwdHash() == masterHash ? new config : new iniFile;
|
2025-07-27 21:56:52 +08:00
|
|
|
|
#else
|
2025-10-15 04:32:59 +08:00
|
|
|
|
m_iniFile = new iniFile;
|
2025-07-27 21:56:52 +08:00
|
|
|
|
#endif
|
2025-06-08 15:38:41 +08:00
|
|
|
|
|
2025-10-15 04:32:59 +08:00
|
|
|
|
srand(static_cast<unsigned int>(time(0)));
|
2019-01-05 20:21:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-11-23 18:13:39 +01:00
|
|
|
|
// 唯一的一个 CMy2015RemoteApp 对象
|
2019-01-05 20:21:43 +08:00
|
|
|
|
|
|
|
|
|
|
CMy2015RemoteApp theApp;
|
|
|
|
|
|
|
2025-11-23 18:13:39 +01:00
|
|
|
|
// 处理服务相关的命令行参数
|
|
|
|
|
|
// 返回值: TRUE 表示已处理服务命令(程序应退出),FALSE 表示继续正常启动
|
|
|
|
|
|
static BOOL HandleServiceCommandLine()
|
|
|
|
|
|
{
|
|
|
|
|
|
CString cmdLine = ::GetCommandLine();
|
|
|
|
|
|
cmdLine.MakeLower();
|
|
|
|
|
|
|
|
|
|
|
|
// -service: 作为服务运行
|
|
|
|
|
|
if (cmdLine.Find(_T("-service")) != -1) {
|
2025-12-09 17:27:50 +01:00
|
|
|
|
int r = ServerService_Run();
|
2025-12-12 14:36:32 +01:00
|
|
|
|
Mprintf("[HandleServiceCommandLine] ServerService_Run %s\n", r ? "failed" : "succeed");
|
2025-11-23 18:13:39 +01:00
|
|
|
|
return TRUE;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// -install: 安装服务
|
|
|
|
|
|
if (cmdLine.Find(_T("-install")) != -1) {
|
2025-12-09 17:27:50 +01:00
|
|
|
|
BOOL r = ServerService_Install();
|
2025-12-12 14:36:32 +01:00
|
|
|
|
Mprintf("[HandleServiceCommandLine] ServerService_Install %s\n", !r ? "failed" : "succeed");
|
2025-11-23 18:13:39 +01:00
|
|
|
|
return TRUE;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// -uninstall: 卸载服务
|
|
|
|
|
|
if (cmdLine.Find(_T("-uninstall")) != -1) {
|
2025-12-09 17:27:50 +01:00
|
|
|
|
BOOL r = ServerService_Uninstall();
|
2025-12-12 14:36:32 +01:00
|
|
|
|
Mprintf("[HandleServiceCommandLine] ServerService_Uninstall %s\n", !r ? "failed" : "succeed");
|
2025-11-23 18:13:39 +01:00
|
|
|
|
return TRUE;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// -agent: 由服务启动的GUI代理模式
|
|
|
|
|
|
// 此模式下正常运行GUI,但使用不同的互斥量名称避免冲突
|
|
|
|
|
|
if (cmdLine.Find(_T("-agent")) != -1) {
|
|
|
|
|
|
// 继续正常启动GUI,但标记为代理模式
|
2025-12-12 14:36:32 +01:00
|
|
|
|
Mprintf("[HandleServiceCommandLine] Run service agent: '%s'\n", cmdLine.GetString());
|
2025-11-23 18:13:39 +01:00
|
|
|
|
return FALSE;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 无参数时,作为服务启动
|
|
|
|
|
|
BOOL registered = FALSE;
|
|
|
|
|
|
BOOL running = FALSE;
|
|
|
|
|
|
char servicePath[MAX_PATH] = { 0 };
|
2025-12-09 17:27:50 +01:00
|
|
|
|
BOOL r = ServerService_CheckStatus(®istered, &running, servicePath, MAX_PATH);
|
2025-12-12 14:36:32 +01:00
|
|
|
|
Mprintf("[HandleServiceCommandLine] ServerService_CheckStatus %s\n", !r ? "failed" : "succeed");
|
2025-12-09 17:27:50 +01:00
|
|
|
|
|
2025-11-23 18:13:39 +01:00
|
|
|
|
char curPath[MAX_PATH];
|
|
|
|
|
|
GetModuleFileNameA(NULL, curPath, MAX_PATH);
|
|
|
|
|
|
|
2025-12-11 11:00:52 +01:00
|
|
|
|
_strlwr(servicePath);
|
|
|
|
|
|
_strlwr(curPath);
|
|
|
|
|
|
BOOL same = (strstr(servicePath, curPath) != 0);
|
|
|
|
|
|
if (registered && !same) {
|
|
|
|
|
|
BOOL r = ServerService_Uninstall();
|
|
|
|
|
|
Mprintf("[HandleServiceCommandLine] ServerService Uninstall %s: %s\n", r ? "succeed" : "failed", servicePath);
|
2025-11-23 18:13:39 +01:00
|
|
|
|
registered = FALSE;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!registered) {
|
2025-12-11 11:00:52 +01:00
|
|
|
|
BOOL r = ServerService_Install();
|
|
|
|
|
|
Mprintf("[HandleServiceCommandLine] ServerService Install: %s\n", r ? "succeed" : "failed", curPath);
|
|
|
|
|
|
return r;
|
2025-11-29 23:22:55 +01:00
|
|
|
|
} else if (!running) {
|
2025-11-23 18:13:39 +01:00
|
|
|
|
int r = ServerService_Run();
|
2025-12-09 17:27:50 +01:00
|
|
|
|
Mprintf("[HandleServiceCommandLine] ServerService Run '%s' %s\n", curPath, r == ERROR_SUCCESS ? "succeed" : "failed");
|
2025-11-23 18:13:39 +01:00
|
|
|
|
if (r) {
|
|
|
|
|
|
r = ServerService_StartSimple();
|
2025-12-09 17:27:50 +01:00
|
|
|
|
Mprintf("[HandleServiceCommandLine] ServerService Start '%s' %s\n", curPath, r == ERROR_SUCCESS ? "succeed" : "failed");
|
2025-11-23 18:13:39 +01:00
|
|
|
|
return r == ERROR_SUCCESS;
|
|
|
|
|
|
}
|
2025-12-09 17:27:50 +01:00
|
|
|
|
return TRUE;
|
2025-11-23 18:13:39 +01:00
|
|
|
|
}
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 检查是否以代理模式运行
|
|
|
|
|
|
static BOOL IsAgentMode()
|
|
|
|
|
|
{
|
|
|
|
|
|
CString cmdLine = ::GetCommandLine();
|
|
|
|
|
|
cmdLine.MakeLower();
|
|
|
|
|
|
return cmdLine.Find(_T("-agent")) != -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// CMy2015RemoteApp 初始化
|
2019-01-05 20:21:43 +08:00
|
|
|
|
|
2025-12-05 21:21:45 +01:00
|
|
|
|
BOOL IsRunningAsAdmin()
|
|
|
|
|
|
{
|
2025-12-21 00:27:40 +01:00
|
|
|
|
BOOL isAdmin = FALSE;
|
|
|
|
|
|
PSID administratorsGroup = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY;
|
|
|
|
|
|
if (AllocateAndInitializeSid(&NtAuthority, 2, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS,
|
|
|
|
|
|
0, 0, 0, 0, 0, 0, &administratorsGroup)) {
|
|
|
|
|
|
if (!CheckTokenMembership(NULL, administratorsGroup, &isAdmin)) {
|
|
|
|
|
|
isAdmin = FALSE;
|
|
|
|
|
|
}
|
2025-12-05 21:21:45 +01:00
|
|
|
|
|
2025-12-21 00:27:40 +01:00
|
|
|
|
FreeSid(administratorsGroup);
|
|
|
|
|
|
}
|
2025-12-05 21:21:45 +01:00
|
|
|
|
|
2025-12-21 00:27:40 +01:00
|
|
|
|
return isAdmin;
|
2025-12-05 21:21:45 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BOOL LaunchAsAdmin(const char* szFilePath, const char* verb)
|
|
|
|
|
|
{
|
2025-12-21 00:27:40 +01:00
|
|
|
|
SHELLEXECUTEINFOA shExecInfo;
|
|
|
|
|
|
ZeroMemory(&shExecInfo, sizeof(SHELLEXECUTEINFOA));
|
|
|
|
|
|
shExecInfo.cbSize = sizeof(SHELLEXECUTEINFOA);
|
|
|
|
|
|
shExecInfo.fMask = SEE_MASK_DEFAULT;
|
|
|
|
|
|
shExecInfo.hwnd = NULL;
|
|
|
|
|
|
shExecInfo.lpVerb = verb;
|
|
|
|
|
|
shExecInfo.lpFile = szFilePath;
|
|
|
|
|
|
shExecInfo.nShow = SW_NORMAL;
|
|
|
|
|
|
|
|
|
|
|
|
return ShellExecuteExA(&shExecInfo);
|
2025-12-05 21:21:45 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-01-05 20:21:43 +08:00
|
|
|
|
BOOL CMy2015RemoteApp::InitInstance()
|
|
|
|
|
|
{
|
2025-12-21 00:27:40 +01:00
|
|
|
|
char curFile[MAX_PATH] = { 0 };
|
|
|
|
|
|
GetModuleFileNameA(NULL, curFile, MAX_PATH);
|
2025-12-09 17:27:50 +01:00
|
|
|
|
if (!IsRunningAsAdmin() && LaunchAsAdmin(curFile, "runas")) {
|
2025-12-12 14:36:32 +01:00
|
|
|
|
Mprintf("[InitInstance] 程序没有管理员权限,用户选择以管理员身份重新运行。\n");
|
2025-12-05 21:21:45 +01:00
|
|
|
|
return FALSE;
|
2025-12-09 17:27:50 +01:00
|
|
|
|
}
|
2025-12-05 21:21:45 +01:00
|
|
|
|
|
2025-11-23 18:13:39 +01:00
|
|
|
|
// 首先处理服务命令行参数
|
|
|
|
|
|
if (HandleServiceCommandLine()) {
|
2025-12-12 14:36:32 +01:00
|
|
|
|
Mprintf("[InitInstance] 服务命令已处理,退出。\n");
|
2025-11-23 18:13:39 +01:00
|
|
|
|
return FALSE; // 服务命令已处理,退出
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-15 04:32:59 +08:00
|
|
|
|
std::string masterHash(GetMasterHash());
|
|
|
|
|
|
std::string mu = GetPwdHash()==masterHash ? "MASTER.EXE" : "YAMA.EXE";
|
2025-06-19 17:50:11 +08:00
|
|
|
|
#ifndef _DEBUG
|
2025-10-15 04:32:59 +08:00
|
|
|
|
{
|
|
|
|
|
|
m_Mutex = CreateMutex(NULL, FALSE, mu.c_str());
|
|
|
|
|
|
if (ERROR_ALREADY_EXISTS == GetLastError()) {
|
|
|
|
|
|
CloseHandle(m_Mutex);
|
|
|
|
|
|
m_Mutex = NULL;
|
2025-12-02 21:45:43 +01:00
|
|
|
|
MessageBox("一个主控程序已经在运行,请检查任务管理器。",
|
2025-12-05 17:40:12 +01:00
|
|
|
|
"提示", MB_ICONINFORMATION);
|
2025-12-09 17:27:50 +01:00
|
|
|
|
Mprintf("[InitInstance] 一个主控程序已经在运行,退出。");
|
2025-10-15 04:32:59 +08:00
|
|
|
|
return FALSE;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-06-19 17:50:11 +08:00
|
|
|
|
#endif
|
2019-01-13 00:04:50 +08:00
|
|
|
|
|
2025-12-12 14:36:32 +01:00
|
|
|
|
Mprintf("[InitInstance] 主控程序启动运行。\n");
|
2025-10-15 04:32:59 +08:00
|
|
|
|
SetUnhandledExceptionFilter(&whenbuged);
|
|
|
|
|
|
|
2025-11-29 14:13:34 +01:00
|
|
|
|
// 创建并显示启动画面
|
|
|
|
|
|
CSplashDlg* pSplash = new CSplashDlg();
|
|
|
|
|
|
pSplash->Create(NULL);
|
|
|
|
|
|
pSplash->UpdateProgressDirect(5, _T("正在初始化系统图标..."));
|
|
|
|
|
|
|
2025-10-15 04:32:59 +08:00
|
|
|
|
SHFILEINFO sfi = {};
|
|
|
|
|
|
HIMAGELIST hImageList = (HIMAGELIST)SHGetFileInfo((LPCTSTR)_T(""), 0, &sfi, sizeof(SHFILEINFO), SHGFI_LARGEICON | SHGFI_SYSICONINDEX);
|
|
|
|
|
|
m_pImageList_Large.Attach(hImageList);
|
|
|
|
|
|
hImageList = (HIMAGELIST)SHGetFileInfo((LPCTSTR)_T(""), 0, &sfi, sizeof(SHFILEINFO), SHGFI_SMALLICON | SHGFI_SYSICONINDEX);
|
|
|
|
|
|
m_pImageList_Small.Attach(hImageList);
|
|
|
|
|
|
|
2025-11-29 14:13:34 +01:00
|
|
|
|
pSplash->UpdateProgressDirect(10, _T("正在初始化公共控件..."));
|
|
|
|
|
|
|
2025-11-23 18:13:39 +01:00
|
|
|
|
// 如果一个运行在 Windows XP 上的应用程序清单指定要
|
|
|
|
|
|
// 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式,
|
|
|
|
|
|
//则需要 InitCommonControlsEx()。否则,将无法创建窗口。
|
2025-10-15 04:32:59 +08:00
|
|
|
|
INITCOMMONCONTROLSEX InitCtrls;
|
|
|
|
|
|
InitCtrls.dwSize = sizeof(InitCtrls);
|
2025-11-23 18:13:39 +01:00
|
|
|
|
// 将它设置为包括所有要在应用程序中使用的
|
|
|
|
|
|
// 公共控件类。
|
2025-10-15 04:32:59 +08:00
|
|
|
|
InitCtrls.dwICC = ICC_WIN95_CLASSES;
|
|
|
|
|
|
InitCommonControlsEx(&InitCtrls);
|
|
|
|
|
|
|
|
|
|
|
|
CWinApp::InitInstance();
|
|
|
|
|
|
|
|
|
|
|
|
AfxEnableControlContainer();
|
|
|
|
|
|
|
2025-11-23 18:13:39 +01:00
|
|
|
|
// 创建 shell 管理器,以防对话框包含
|
|
|
|
|
|
// 任何 shell 树视图控件或 shell 列表视图控件。
|
2025-10-15 04:32:59 +08:00
|
|
|
|
CShellManager *pShellManager = new CShellManager;
|
|
|
|
|
|
|
2025-11-23 18:13:39 +01:00
|
|
|
|
// 标准初始化
|
|
|
|
|
|
// 如果未使用这些功能并希望减小
|
|
|
|
|
|
// 最终可执行文件的大小,则应移除下列
|
|
|
|
|
|
// 不需要的特定初始化例程
|
|
|
|
|
|
// 更改用于存储设置的注册表项
|
|
|
|
|
|
// TODO: 应适当修改该字符串,
|
|
|
|
|
|
// 例如修改为公司或组织名
|
2025-10-15 04:32:59 +08:00
|
|
|
|
SetRegistryKey(_T("YAMA"));
|
|
|
|
|
|
|
|
|
|
|
|
CMy2015RemoteDlg dlg(nullptr);
|
|
|
|
|
|
m_pMainWnd = &dlg;
|
|
|
|
|
|
INT_PTR nResponse = dlg.DoModal();
|
|
|
|
|
|
if (nResponse == IDOK) {
|
2025-11-23 18:13:39 +01:00
|
|
|
|
// TODO: 在此放置处理何时用
|
|
|
|
|
|
// “确定”来关闭对话框的代码
|
2025-10-15 04:32:59 +08:00
|
|
|
|
} else if (nResponse == IDCANCEL) {
|
2025-11-23 18:13:39 +01:00
|
|
|
|
// TODO: 在此放置处理何时用
|
|
|
|
|
|
// “取消”来关闭对话框的代码
|
2025-10-15 04:32:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-23 18:13:39 +01:00
|
|
|
|
// 删除上面创建的 shell 管理器。
|
2025-10-15 04:32:59 +08:00
|
|
|
|
if (pShellManager != NULL) {
|
|
|
|
|
|
delete pShellManager;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-23 18:13:39 +01:00
|
|
|
|
// 由于对话框已关闭,所以将返回 FALSE 以便退出应用程序,
|
|
|
|
|
|
// 而不是启动应用程序的消息泵。
|
2025-10-15 04:32:59 +08:00
|
|
|
|
return FALSE;
|
2019-01-05 20:21:43 +08:00
|
|
|
|
}
|
2019-01-13 00:04:50 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int CMy2015RemoteApp::ExitInstance()
|
|
|
|
|
|
{
|
2025-10-15 04:32:59 +08:00
|
|
|
|
if (m_Mutex) {
|
|
|
|
|
|
CloseHandle(m_Mutex);
|
|
|
|
|
|
m_Mutex = NULL;
|
|
|
|
|
|
}
|
|
|
|
|
|
__try {
|
|
|
|
|
|
Delete();
|
|
|
|
|
|
} __except(EXCEPTION_EXECUTE_HANDLER) {
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SAFE_DELETE(m_iniFile);
|
|
|
|
|
|
|
2025-11-23 18:13:39 +01:00
|
|
|
|
// 只有在代理模式退出时才停止服务
|
|
|
|
|
|
if (IsAgentMode()) {
|
|
|
|
|
|
ServerService_Stop();
|
2025-12-12 14:36:32 +01:00
|
|
|
|
Mprintf("[InitInstance] 主控程序为代理模式,停止服务。\n");
|
2025-11-23 18:13:39 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-12 14:36:32 +01:00
|
|
|
|
Mprintf("[InitInstance] 主控程序退出运行。\n");
|
|
|
|
|
|
Sleep(1000);
|
2025-12-09 17:27:50 +01:00
|
|
|
|
|
2025-10-15 04:32:59 +08:00
|
|
|
|
return CWinApp::ExitInstance();
|
2019-01-13 00:04:50 +08:00
|
|
|
|
}
|