抛弃GdCpp*.dll/pdb历史重新建库。libhv和Sqlite的dll保留
This commit is contained in:
52
include/ProcessHelper.h
Normal file
52
include/ProcessHelper.h
Normal file
@@ -0,0 +1,52 @@
|
||||
#pragma once
|
||||
|
||||
GDCPP_API struct sProcessInfo {
|
||||
std::wstring name;
|
||||
DWORD pid;
|
||||
|
||||
sProcessInfo(const std::wstring& n=L"", DWORD p = 0)
|
||||
: name(n), pid(p) {
|
||||
}
|
||||
|
||||
// 复制构造函数
|
||||
sProcessInfo(const sProcessInfo& other)
|
||||
: name(other.name), pid(other.pid) {
|
||||
}
|
||||
|
||||
// 赋值运算符
|
||||
sProcessInfo& operator=(const sProcessInfo& other) {
|
||||
if (this != &other) {
|
||||
name = other.name;
|
||||
pid = other.pid;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// 查找正在运行的目标进程,返回数量,并将找到的进程写入 outFoundProcs。
|
||||
// 输入outFoundProcs如果为空,则查找结果以追加方式写入;
|
||||
// 如果outFoundProcs大小与targetProcs相同,则将找到的进程写入对应位置。
|
||||
// 示例
|
||||
//std::vector<std::wstring> MonitorAppName = { L"GdCamExpert", L"GoodVision" };
|
||||
//std::vector<sProcessInfo> MonitorAppStatus;
|
||||
//MonitorAppStatus.resize(MonitorAppName.size());
|
||||
//int runningCount = FindRunningProcesses_BeginWith(MonitorAppName, MonitorAppStatus);
|
||||
// 两个版本:
|
||||
// 1. FindRunningProcesses_BeginWith:查找进程名以目标字符串开头的进程
|
||||
// 2. FindRunningProcesses_Exact:查找进程名完全匹配目标字符串的进程
|
||||
// 都不区分大小写。
|
||||
GDCPP_API int FindRunningProcesses_BeginWith(const std::vector<std::wstring>& targetProcs, std::vector<sProcessInfo>& outFoundProcs);
|
||||
GDCPP_API int FindRunningProcesses_Exact(const std::vector<std::wstring>& targetProcs, std::vector<sProcessInfo>& outFoundProcs);
|
||||
|
||||
|
||||
// 请求关机或重启,EWX_SHUTDOWN、EWX_REBOOT
|
||||
// cmd: EWX_SHUTDOWN, EWX_REBOOT, EWX_POWEROFF 等
|
||||
// reason: SHTDN_REASON_MAJOR_OPERATINGSYSTEM, SHTDN_REASON_MINOR_OTHER 等
|
||||
GDCPP_API void DoShutdown(uint32_t cmd = EWX_SHUTDOWN, DWORD reason = SHTDN_REASON_MAJOR_OPERATINGSYSTEM);
|
||||
GDCPP_API BOOL IsProcessRunning(LPCTSTR pszProcName, LPTSTR pFoundName, DWORD dwFoundLen);
|
||||
|
||||
GDCPP_API bool StartProcessAndGetPid(const fs::path& exePath, DWORD* outPid);
|
||||
GDCPP_API bool StartProcessIndependently(const fs::path& exePath);
|
||||
|
||||
GDCPP_API bool NotifyProcessToExit(DWORD pid, DWORD timeoutMs = 1000);
|
||||
Reference in New Issue
Block a user