Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Dec 7th, 2004, 6:18 PM   #1
cl0ckw0rk_ninj4
Newbie
 
Join Date: Dec 2004
Posts: 8
Rep Power: 0 cl0ckw0rk_ninj4 is on a distinguished road
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
cl0ckw0rk_ninj4 is offline   Reply With Quote
Old Mar 15th, 2005, 10:23 AM   #2
MrLee
Newbie
 
Join Date: Mar 2005
Location: South Wales, UK
Posts: 9
Rep Power: 0 MrLee is on a distinguished road
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:
The impossible is often the untried.
MrLee is offline   Reply With Quote
Old Mar 15th, 2005, 5:11 PM   #3
Rory
Expert Programmer
 
Rory's Avatar
 
Join Date: Jan 2005
Location: London
Posts: 542
Rep Power: 4 Rory is on a distinguished road
Send a message via MSN to Rory
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
Rory is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 1:23 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC