gpt4 book ai didi

c++ - 检查 CWinApp 是否存在

转载 作者:行者123 更新时间:2023-11-28 08:02:41 27 4
gpt4 key购买 nike

我有一个被编程和使用的过程

CWinApp(
LPCTSTR lpszAppName = NULL
);

我知道 lpszAppName。

通过 lpszAppName,我想检查这个 WinApp 进程是否存在。我该怎么做?

谢谢

最佳答案

使用命名互斥体:

在程序的开头:

HANDLE hMutex = CreateMutex(NULL, TRUE, "Your program name");
if (GetLastError() == ERROR_ALREADY_EXISTS)
{
// Process already running.
CloseHandle(hMutex);
}
else
{
// No process running.
}

程序结束时:

if (hMutex)
{
CloseHandle(hMutex);
hMutex = NULL;
}

关于c++ - 检查 CWinApp 是否存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10978914/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com