使用命名对象来防止运行一个应用程序的多个实例

什么是内核对象?参考这里:

http://www.cnblogs.com/vivilisa/archive/2009/03/09/1407277.html

使用命名对象来防止运行一个应用程序的多个实例

代码如下:



int WINAPI _tWinMain(HINSTANCE hInstExe, HINSTANCE, PTSTR pszCmdLine, int nCmdShow)
{
    HANDLE h 
= CreateMutex(NULL, FALSE, TEXT("{b2e42b57-8ee3-11df-bb01-846a855c3e23}"));
    
    
if(GetLastError() == ERROR_ALREADY_EXISTS)
    {
        CloseHandle(h);
        
return(0);
    }

    
// This is the first instance of this application running.
    
// ...
    
// Before exiting, close the object.
    CloseHandle(h);
    
return(0);
}

原文地址:https://www.cnblogs.com/bruceleeliya/p/1776957.html