Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Visual Basic (http://www.programmingforums.org/forum18.html)
-   -   Createmutex Help??? (http://www.programmingforums.org/showthread.php?t=1461)

cl0ckw0rk_ninj4 Dec 7th, 2004 7:18 PM

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

MrLee Mar 15th, 2005 11:23 AM

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.

Rory Mar 15th, 2005 6:11 PM

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



All times are GMT -5. The time now is 3:23 AM.

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