~ubuntu-branches/debian/squeeze/stella/squeeze

« back to all changes in this revision

Viewing changes to src/win32/StellaX/main.cxx

  • Committer: Bazaar Package Importer
  • Author(s): Mario Iseli
  • Date: 2006-04-08 18:38:25 UTC
  • mfrom: (1.1.2 upstream) (2.1.1 etch)
  • Revision ID: james.westby@ubuntu.com-20060408183825-vu1jk57rk929derx
* New Maintainer (Closes: #361345)
* New upstream release (Closes: #349725)
* Build-Depend now on libslang2-dev (Closes: #325577)
* Complete rebuild of debian/, upgraded to policy-standards
  3.6.2 and compat-level 5.
* Removed stellarc since stella only reads ~/.stellarc and even
  works without a first config.
* New debian/watch file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//============================================================================
2
 
//
3
 
//   SSSS    tt          lll  lll          XX     XX
4
 
//  SS  SS   tt           ll   ll           XX   XX
5
 
//  SS     tttttt  eeee   ll   ll   aaaa     XX XX
6
 
//   SSSS    tt   ee  ee  ll   ll      aa     XXX
7
 
//      SS   tt   eeeeee  ll   ll   aaaaa    XX XX
8
 
//  SS  SS   tt   ee      ll   ll  aa  aa   XX   XX
9
 
//   SSSS     ttt  eeeee llll llll  aaaaa  XX     XX
10
 
//
11
 
// Copyright (c) 1995-2000 by Jeff Miller
12
 
// Copyright (c) 2004 by Stephen Anthony
13
 
//
14
 
// See the file "license" for information on usage and redistribution of
15
 
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
16
 
//
17
 
// $Id: main.cxx,v 1.3 2004/07/15 03:03:27 stephena Exp $
18
 
//============================================================================
19
 
 
20
 
#include "pch.hxx"
21
 
#include "resource.h"
22
 
 
23
 
#include "GlobalData.hxx"
24
 
#include "MainDlg.hxx"
25
 
 
26
 
class CSingleInstance
27
 
{
28
 
  public:
29
 
    CSingleInstance( LPCTSTR pszName )
30
 
    {
31
 
      ::SetLastError( ERROR_SUCCESS );
32
 
      m_hMutex = ::CreateMutex( NULL, TRUE, pszName );
33
 
      m_dwError = ::GetLastError();
34
 
    }
35
 
 
36
 
    ~CSingleInstance()
37
 
    {
38
 
      if ( m_hMutex != INVALID_HANDLE_VALUE && m_dwError != ERROR_ALREADY_EXISTS )
39
 
      {
40
 
        VERIFY( ::ReleaseMutex( m_hMutex ) );
41
 
        VERIFY( ::CloseHandle( m_hMutex ) );
42
 
      }
43
 
    }
44
 
 
45
 
    BOOL AlreadyExists( void ) const
46
 
    {
47
 
      return ( m_dwError == ERROR_ALREADY_EXISTS );
48
 
    }
49
 
 
50
 
  private:
51
 
    HANDLE m_hMutex;
52
 
    DWORD m_dwError;
53
 
 
54
 
    CSingleInstance( const CSingleInstance& );  // no implementation
55
 
    void operator=( const CSingleInstance& );  // no implementation
56
 
};
57
 
 
58
 
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
59
 
LPCTSTR g_ctszDebugLog = _T("stella.log");
60
 
 
61
 
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
62
 
int WINAPI _tWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
63
 
                      LPTSTR lpCmdLine, int nCmdShow )
64
 
{
65
 
  UNUSED_ALWAYS( hPrevInstance );
66
 
  UNUSED_ALWAYS( lpCmdLine );
67
 
  UNUSED_ALWAYS( nCmdShow );
68
 
 
69
 
  (void)::DeleteFile(g_ctszDebugLog);
70
 
 
71
 
  CSingleInstance mutex( _T("StellaXMutex") );
72
 
  if ( mutex.AlreadyExists() )
73
 
  {
74
 
    MessageBox( hInstance, NULL, IDS_ALREADYRUNNING );
75
 
    return 1;
76
 
  }
77
 
 
78
 
  HRESULT hrCoInit = ::CoInitialize( NULL );
79
 
  if ( FAILED(hrCoInit) )
80
 
    MessageBox( hInstance, NULL, IDS_COINIT_FAILED );
81
 
 
82
 
  ::InitCommonControls();
83
 
 
84
 
  CGlobalData globaldata( hInstance );
85
 
 
86
 
  // show the ui
87
 
  MainDlg dlg( globaldata, hInstance );
88
 
  dlg.DoModal( NULL );
89
 
 
90
 
  if ( hrCoInit == S_OK )
91
 
    ::CoUninitialize();
92
 
 
93
 
  return 0;
94
 
}