~ubuntu-branches/ubuntu/karmic/notecase/karmic

« back to all changes in this revision

Viewing changes to src/_win/SingleInstanceWin.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Vijay(Vijay)
  • Date: 2007-06-14 00:13:48 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20070614001348-z9e2vbgtenb9nhoo
Tags: 1.5.6-0ubuntu1
* New Upstream release 
*  The libgnomevfs2-dev is also added to Build-Depends 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
////////////////////////////////////////////////////////////////////////////
 
2
// NoteCase notes manager project <http://notecase.sf.net>
 
3
//
 
4
// This code is licensed under BSD license.See "license.txt" for more details.
 
5
//
 
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
////////////////////////////////////////////////////////////////////////////
 
9
 
 
10
#include "SingleInstance.h"
 
11
 
 
12
CSingleInstance::CSingleInstance(const char *szName)
 
13
{
 
14
        m_bAlreadyExists = false;
 
15
 
 
16
        // try to create the named mutex
 
17
    m_hMutex = CreateMutex(NULL, FALSE, szName);
 
18
        if (GetLastError() == ERROR_ALREADY_EXISTS)
 
19
                m_bAlreadyExists = true;
 
20
}
 
21
 
 
22
CSingleInstance::~CSingleInstance()
 
23
{
 
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);
 
28
    }
 
29
}
 
30
 
 
31
bool CSingleInstance::ProgramAlreadyStarted()
 
32
{
 
33
        return m_bAlreadyExists;
 
34
}
 
35
 
 
36