03-1防止程序有多个实例运行

01-CreateMutex

作用是找出当前系统是否已经存在指定进程的实例。如果没有则创建一个互斥体

例如:

 1 int main()
 2 {
 3     HANDLE m_hMutex = CreateMutex(NULL, FALSE, TEXT("jerry"));
 4     if (GetLastError() == ERROR_ALREADY_EXISTS)
 5     {
 6         return 0;
 7     }
 8     else
 9     {
10         printf("The instance does not exist!");
11     }
12 
13     getchar();
14     return 0;
15 }
原文地址:https://www.cnblogs.com/luoyefeiwu/p/4771883.html