Click to See Complete Forum and Search --> : Mutexes


Green_Beret
October 11th, 2001, 09:26 PM
Does anyone know how to use the CreateMutex,
ResumeMutex and WaitForSingleObject APIs?

An example would be very helpful.

Thanks in advance.
Regards,
The Beret.



Regards,
The Beret.

bigfredb
October 16th, 2001, 04:10 PM
here is some code for create mutex:


'declarations
Global ThisAppMutex as Long
Global hInstanceMutex as Long

public Declare Function OpenMutex& Lib "kernel32" Alias "OpenMutexA" (byval dwDesiredAccess as Long, byval bInheritHandle as Long, byval lpName as string)
public Declare Function CreateMutex Lib "kernel32" Alias "CreateMutexA" (byval lpMutexAttributes as Long, byval bInitialOwner as Long, byval lpName as string) as Long
public Declare Function CloseHandle Lib "kernel32" (byval hObject as Long) as Long
public Declare Function GetLastError Lib "kernel32" () as Long


'create mutex
Dim hInstanceMutexHandle as Long
Dim MutexHandle as Long
hInstanceMutexHandle = CreateMutex(0, true, "SomeValueYouSet")
If (Err.LastDllError = ERROR_ALREADY_EXISTS) then
If (hInstanceMutexHandle) then
Call CloseHandle(hInstanceMutexHandle)
End
End If
End If
ThisAppMutex = hInstanceMutexHandle





Hope this helps.