tags:

views:

226

answers:

1

I created a mutex in one app; the code is:

HANDLE global_mutex = CreateMutex(NULL, FALSE, "mcdonalds");
if(global_mutex)
{
    wxLogMessage("created successfully.");
}
else
{
    wxLogFatalError("Unable to create the mutex");
}

then I read it from my other program

Public Declare Function GetLastError Lib "kernel32" () As Long

Public Declare Function OpenMutex Lib "Kernel32" _
Alias "OpenMutex" (ByRef dwDesiredAccess As Integer, ByVal bInheritHandle As Boolean, _
ByVal lpName As String) As Long




Dim SingleAppHandle As Long
Dim MutexName As String
MutexName = "mcdonalds"
    SingleAppHandle = OpenMutex(0, 0, MutexName)
If SingleAppHandle = 0 Then
 Dim error_number
 error_number = GetLastError()
 MessageBox error_number
Else
 [DO STUFF]
End If

However, I keep getting openmutex returning NULL and lasterror set to 1314 which is ERROR_PRIVILEGE_NOT_HELD

Running on Windows XP Pro sp3

A: 

Try with the first parameter set to MUTEX_ALL_ACCESS (&H1F0001)

Has been too long since I did it myself, but I found that example on the net

vdr
Thanks. Now it seems to be returning something valid (instead of NULL) but when the first app exits (the one that called CreateMutex), the mutex seems to still be around because the second app (calls OpenMutex) still gets returned a valid pointer instead of 0 as I would expect. Any ideas? I'm new to this mutex thing.
Memb
Ok, I wasn't calling CloseHandle. Everything works now! Thank you.
Memb