Winapi Can';t读取使用Createmutex创建的全局互斥体
我在一个应用程序中创建了互斥;代码是:Winapi Can';t读取使用Createmutex创建的全局互斥体,winapi,Winapi,我在一个应用程序中创建了互斥;代码是: HANDLE global_mutex = CreateMutex(NULL, FALSE, "mcdonalds"); if(global_mutex) { wxLogMessage("created successfully."); } else { wxLogFatalError("Unable to create the mutex"); } 然后我从我的另一个程序中读到它 Public Declare Function GetL
HANDLE global_mutex = CreateMutex(NULL, FALSE, "mcdonalds");
if(global_mutex)
{
wxLogMessage("created successfully.");
}
else
{
wxLogFatalError("Unable to create the mutex");
}
然后我从我的另一个程序中读到它
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
然而,我不断地让openmutex返回NULL,并将lasterror设置为1314,这是错误\u特权\u未\u保持
在Windows XP Pro sp3上运行尝试将第一个参数设置为
MUTEX\u ALL\u ACCESS
(&h1f001
)
我已经很久没有亲自做了,但是我在网上发现了,谢谢。现在它似乎返回了一些有效的东西(而不是NULL),但是当第一个应用程序退出(调用CreateMutex的应用程序)时,互斥锁似乎仍然存在,因为第二个应用程序(调用OpenMutex)仍然返回了一个有效指针,而不是我所期望的0。有什么想法吗?我对互斥是个新手。好吧,我不是在给CloseHandle打电话。现在一切都好了!非常感谢。