![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Dec 2004
Posts: 8
Rep Power: 0
![]() |
can someone tell me how to use the createmutex command to make a program runs its counterpart program after closing it
lets say program1- does anything i want, and it gets closed program2 - i want this one to know when the first one is closed and re open it |
|
|
|
|
|
#2 | |
|
Newbie
Join Date: Mar 2005
Location: South Wales, UK
Posts: 9
Rep Power: 0
![]() |
I can't say I am aware of the createmutex command but there are other ways for one application to 'know' when another has closed. Quite easily if they are both written by yourself. Please elaborate.
__________________
Mr Lee Quote:
|
|
|
|
|
|
|
#3 |
|
Expert Programmer
|
Well, conventionally you use a mutex like this, though if you have two programs running in parallel you'd need to check for the mutex's existence periodically using a timer or a loop WITH A SLEEP STATEMENT IN IT (the number of BSOD's...). In fact you'd be better off using a hooked atom, checking the task list or actually actively notifying the program's counterpart through DDE, a window message or whatever.
Const ERROR_ALREADY_EXISTS = 183&
Private Declare Function CreateMutex Lib "kernel32" Alias "CreateMutexA" (lpMutexAttributes As Any, ByVal bInitialOwner As Long, ByVal lpName As String) As Long
Private Declare Function ReleaseMutex Lib "kernel32" (ByVal hMutex As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Sub Form_Load()
Dim hMutex As Long
'Try to create a new Mutex
hMutex = CreateMutex(ByVal 0&, 1, App.Title)
'Did the mutex already exist?
If (Err.LastDllError = ERROR_ALREADY_EXISTS) Then
'Clean up
ReleaseMutex hMutex
CloseHandle hMutex
'More than one instance detected
MsgBox "More than one instance"
End
Else
'form load code
End If
End Sub |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|