Mutex

delphi package - automated exception handling

Mutex

Postby emailaya » Fri Sep 23, 2016 11:10 am

My code is this:

Code: Select all
Mutex := CreateMutex(nil, True, 'app');  <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  try
    if (Application.ExeName = 'app.exe') and ((Mutex = 0) or (GetLastError = ERROR_ALREADY_EXISTS)) then
      ShowMessage ('app is already running')
    else
    begin
      Application.Initialize;
      Application.MainFormOnTaskbar := True;
      Application.CreateForm(TfrmMain, frmMain);
      Application.Run;
    end;
  finally
    ReleaseMutex(Mutex);  <<<<<<<<<<<<<<<<<<<<<<<<
  end;


As you can see, I create the mutex and release it (a breakpoint shows the releasing is done when closing the application), still madexcept gives me the following report:

Code: Select all
allocation number: 35332
program up time: 743 ms
type: Mutex Handle
handle: $99c
access rights: $1f0001
name: \Sessions\1\BaseNamedObjects\app

main thread ($a64):
671ccc16 madExcept32.dll madExceptDbg    3538 CreateMutexWCallback
00416df2 app.exe    Winapi.Windows 35136 CreateMutex
01329f79 app.exe    app          24 initialization
774e38f2 KERNEL32.DLL                         BaseThreadInitThunk


What am I missing?
Thanks
emailaya
 
Posts: 249
Joined: Thu Oct 13, 2005 11:33 am

Re: Mutex

Postby madshi » Mon Sep 26, 2016 8:34 am

ReleaseMutex does *not* free the mutex, it just changes the state of the mutex. You need to use CloseHandle to free the mutex.
madshi
Site Admin
 
Posts: 9431
Joined: Sun Mar 21, 2004 5:25 pm

Re: Mutex

Postby emailaya » Mon Sep 26, 2016 9:14 am

Will try and update, thanks
emailaya
 
Posts: 249
Joined: Thu Oct 13, 2005 11:33 am


Return to madExcept

Who is online

Users browsing this forum: No registered users and 3 guests