I create a mutex at the start of the my application, primarily to prevent running 2 instances of same application.
if CreateMutex(nil,false,'Proton Studio') = 0 then
RaiseLastOSError;
if GetLastError = ERROR_ALREADY_EXISTS then exit;
However, when I reconfigure my application I need to release the mutex before the application is closed in order to start a short program which will then restart my application.
hw := OpenMutex(MUTEX_ALL_ACCESS, false, 'Proton Studio');
if ReleaseMutex(hw)then begin
if ShellExecute(application.Handle, 'open',
Pchar('StudioRestart.exe'), PChar(Application.ExeName),'', SW_SHOWNORMAL) > 32 then
fmIDEMain.Close
else
ShowMessage('Unable to Restart, please close and restart manually')
end
OpenMutex returns a handle but when I call ReleaseMutex the function returns false. How should I close this mutex?