1
////////////////////////////////////////////////////////////////////////////
2
// NoteCase notes manager project <http://notecase.sf.net>
4
// This code is licensed under BSD license.See "license.txt" for more details.
6
// File: object of this class should be alive as long as program lives
7
// so that instance can be detected (by using named mutex object)
8
////////////////////////////////////////////////////////////////////////////
10
#include "SingleInstance.h"
12
CSingleInstance::CSingleInstance(const char *szName)
14
m_bAlreadyExists = false;
16
// try to create the named mutex
17
m_hMutex = CreateMutex(NULL, FALSE, szName);
18
if (GetLastError() == ERROR_ALREADY_EXISTS)
19
m_bAlreadyExists = true;
22
CSingleInstance::~CSingleInstance()
24
//after this we won't be able to detect this instance
25
if (m_hMutex != NULL) {
26
ReleaseMutex(m_hMutex);
27
CloseHandle(m_hMutex);
31
bool CSingleInstance::ProgramAlreadyStarted()
33
return m_bAlreadyExists;