//---------------------------------------------------------------------------- // EgalTech 2023-2023 //---------------------------------------------------------------------------- // File : EXE_Mutex.cpp Data : 05.02.23 Versione : 2.5a6 // Contenuto : Funzioni per gestione mutex. // // // // Modifiche : 05.02.23 DS Creazione modulo. // // //---------------------------------------------------------------------------- //--------------------------- Include ---------------------------------------- #include "stdafx.h" #include "EXE.h" #include "/EgtDev/Include/EgtStringConverter.h" using namespace std ; //---------------------------------------------------------------------------- static HANDLE s_hMutex = NULL ; //---------------------------------------------------------------------------- bool ExeCreateMutex( const string& sMutexName) { if ( s_hMutex != NULL) return false ; HANDLE hMutex = CreateMutex( NULL, TRUE, stringtoW( sMutexName)) ; if ( hMutex == NULL) return false ; else if ( GetLastError() == ERROR_ALREADY_EXISTS) { ReleaseMutex( hMutex) ; CloseHandle( hMutex) ; return false ; } else { s_hMutex = hMutex ; return true ; } } //---------------------------------------------------------------------------- bool ExeReleaseMutex( void) { if ( s_hMutex == NULL) return true ; bool bOk = ( ReleaseMutex( s_hMutex) != FALSE) ; CloseHandle( s_hMutex) ; s_hMutex = NULL ; return bOk ; }