windows 之互斥量
标签:
CreateMutexA CreateMutexExA CreateMutexExW CreateMutexW可以用互斥量作为单实例应用控制,
如:
进程A创建互斥量Mutex,,
启动进程B创建互斥量Mutex失败,这时候就不打开进程B而是打开进程A
HANDLE hMutex = ::CreateMutexW(NULL, FALSE, ptr);
if (hMutex == NULL)
{
std::cout << "create mutex error with." << GetLastError() << std::endl;
}
else {
std::cout << "create mutex successful." << std::endl;
}
if (ERROR_ALREADY_EXISTS == GetLastError())
{
cout << "mutex has exists" << endl;
}
else
{
cout << "create new muetex" << endl;
}
//记得创建完后释放互斥量.
CloseHandle(hMutex);
windows 之互斥量----mutex
标签:
原文地址:https://www.cnblogs.com/liuruoqian/p/12979863.html
温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/43618.html