|
From: andrew7 <bd...@us...> - 2007-06-18 01:48:45
|
Update of /cvsroot/smartwin/SmartWin/source In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv16468 Modified Files: Application.cpp Log Message: Remove \ characters from mutex name so isAppAlreadyRunning() would work. Index: Application.cpp =================================================================== RCS file: /cvsroot/smartwin/SmartWin/source/Application.cpp,v retrieving revision 1.47 retrieving revision 1.48 diff -u -d -r1.47 -r1.48 --- Application.cpp 15 Jun 2007 22:22:28 -0000 1.47 +++ Application.cpp 18 Jun 2007 01:48:42 -0000 1.48 @@ -208,15 +208,21 @@ bool Application::isAppAlreadyRunning() { + // Construct an application unique string without '\' characters. SmartUtil::tstring appPath = getModulePath() + getModuleFileName(); + SmartUtil::tstring::size_type p = 0; + while( (p = appPath.find(_T('\\'), p)) != SmartUtil::tstring::npos ) { + appPath[p] = _T('_'); + } + + // Since this can only be done once, we know if the app is already running. itsMutex = ::CreateMutex( NULL, FALSE, appPath.c_str() ); if ( !itsMutex ) - return false; - if ( ::GetLastError() == ERROR_ALREADY_EXISTS ) - { + return false; // I created the Mutex, so I'm the first. + if ( ::GetLastError() == ERROR_ALREADY_EXISTS ) { ::CloseHandle( itsMutex ); itsMutex = 0; - return true; + return true; // I'm the second application instance. } else { |