Login  Register

How to CreateMutex in Dolphin?

Posted by talios@gmail.com on Sep 22, 2004; 5:12am
URL: https://forum.world.st/How-to-CreateMutex-in-Dolphin-tp3371535.html

I've just hit a situation where I'd like to trap my installer from installing/uninstalling in the system if/when theres a named mutex running from my application.

Quoting from the InnoSetup documentation:

This directive is used to prevent the user from installing new versions of an application while the application is still running, and to prevent the user from uninstalling a running application. It specifies the names of one or more named mutexes (multiple mutexes are separated by commas), which Setup and Uninstall will check for at startup. If any exist, Setup/Uninstall will display the message: "[Setup or Uninstall] has detected that [AppName] is currently running. Please close all instances of it now, then click OK to continue, or Cancel to exit."

Use of this directive requires that you add code to your application which creates a mutex with the name you specify in this directive. Examples of creating a mutex in Delphi, C, and Visual Basic are shown below. The code should be executed during your application's startup.
Delphi:

CreateMutex(nil, False, 'MyProgramsMutexName');

C:

CreateMutex(NULL, FALSE, "MyProgramsMutexName");

Visual Basic (submitted by Peter Young):

'Place in Declarations section:
Private Declare Function CreateMutex Lib "kernel32" _
        Alias "CreateMutexA" _
       (ByVal lpMutexAttributes As Long, _
        ByVal bInitialOwner As Long, _
        ByVal lpName As String) As Long

'Place in startup code (Form_Load or Sub Main):
CreateMutex 0&, 0&, "MyProgramsMutexName"

It is not necessary to explicitly destroy the mutex object upon your application's termination; the system will do this automatically. Nor is it recommended that you do so, because ideally the mutex object should exist until the process completely terminates.
Note that mutex name comparison in Windows is case sensitive.
See the topic for CreateMutex in the MS SDK help for more information on mutexes.
However, I can't seem to find anything that matches/implements CreateMutex in Dolphin anywhere, the Mutex class doesn't quite seem to be what I'm after, and there doesn't seem to be anything in KernelLibrary, the closest thing I could find sounding like what I want being:

  KernelLibrary
    createEvent: aSECURITYATTRIBUTES bManualReset: aBoolManual
      bInitialState: aBoolState lpName: aStringPathName

Do I maybe have to import/declare this Win32 API function myself or?