Run only one instance of your application: Difference between revisions

no edit summary
No edit summary
Line 10: Line 10:
Here is the code if you want to go that route."
Here is the code if you want to go that route."


In the SRC file:
In the SRC file within the panel Object put this piece of code:
 
Procedure Exit_Application
     Procedure Exit_Application
     integer iVoid
        If (ghMuteX) Move (CloseHandle(ghMutex)) to giTemp
    If (ghMuteX) Move (CloseHandle(ghMutex)) to iVoid
        Forward Send Exit_Application
    move 0 to iVoid
    End_Procedure
    Forward Send Exit_Application
 
End_Procedure
//In a package that gets hit on startup:
And in a package that gets hit on startup:
 
// Constants
Define ERROR_INVALID_HANDLE        for 6    //  taken from error.h of VS7
Define ERROR_ALREADY_EXISTS        for 183
//
  Handle ghMuteX
  Handle ghMuteX
 
// external functions
  #IFNDEF Get_CreateMuteX
  #IFNDEF Get_CreateMuteX
External_Function CreateMuteX "CreateMutexA" Kernel32.dll Integer i1 Integer i2 Integer i3 Returns Integer
    External_Function CreateMuteX "CreateMutexA" Kernel32.dll Integer i1 Integer i2 Integer i3 Returns Integer
  #ENDIF
  #ENDIF
  #IFNDEF Get_CloseHandle
  #IFNDEF Get_CloseHandle
External_Function CloseHandle "CloseHandle" Kernel32.dll Integer i1 Returns Integer
    External_Function CloseHandle "CloseHandle" Kernel32.dll Integer i1 Returns Integer
  #ENDIF
  #ENDIF
 
  // function to create a mutex
  // CLIENT and SERVER
  Procedure Create_MuteX_Object
  Procedure Create_MuteX_Object
     Integer iVoid iErr
     Integer iVoid iErr
Line 43: Line 44:
             // kill the application here if you do not want to allow  
             // kill the application here if you do not want to allow  
             // multiple instances
             // multiple instances
            ABORT
         End
         End
         Else Send None  // program is not already running
         Else Send None  // program is not already running
Line 48: Line 50:
     Else Send None  // rare error; object could not be created
     Else Send None  // rare error; object could not be created
  End_Procedure  // Create_MuteX_Object
  End_Procedure  // Create_MuteX_Object
 
// create the mutex
  Send Create_MuteX_Object
  Send Create_MuteX_Object
=== Using FindWindow WinAPI ===
=== Using FindWindow WinAPI ===


3

edits