#include
#include <windows.h>
class single_application {
public:
~single_application() {
#ifdef WIN32_WINNT
ReleaseMutex(mutex);
#endif
}
bool is_runing(const std::string& mutex_name) {
#ifdef WIN32_WINNT
mutex = OpenMutexA(MUTEX_ALL_ACCESS, 0, mutex_name.c_str());
if (nullptr == mutex_)
{
mutex_ = CreateMutexA(0, 0, mutex_name.c_str());
return false;
}
else
{
auto out_put = mutex_name + " is running, so exit!\n";
std::cout << out_put << std::endl;
return true;
}
#else
std::cout << “has not realize” << std::endl;
return true;
#endif
}
private:
#ifdef WIN32_WINNT
HANDLE mutex;
#endif
};
int main()
{
single_application single;
if (single.is_runing(“QQ”))
{
return 0;
}
}