天天看點

15.5 保證應用程式隻有一個執行個體運作(Mutex)

#include <iostream>

#include <Windows.h>

using namespace std;

int main()

{

    HANDLE hMutex = CreateMutex(NULL,TRUE,L"OnlyInstance");

    if (hMutex)

    {

        if (ERROR_ALREADY_EXISTS == GetLastError())

        {

            cout<<"Already exist"<<endl;

            return 0;

        }

        else

        {

            cout<<"An instance"<<endl;

        }

    }

    else

    {

        cout<<"ERROR_INVALID_HANDLE"<<endl;

    }

    system("pause");

    return 0;

}

轉載于:https://www.cnblogs.com/BeyondTechnology/archive/2010/08/30/1813092.html