Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我们有多个 MFC 应用程序,它们使用 CMutex(false, "blah"),其中 "blah" 允许互斥锁跨进程边界工作。
其中一个应用程序是在没有 MFC 的情况下重写的(改用 Qt)。如何使用 Win32 调用模拟 CMutex?(Qt 的 QMutex 不是进程间的。)我不想修改 MFC 应用程序。
对于进程间互斥体,您需要以下调用:
创建互斥体 等待单个对象 释放互斥锁 关闭手柄
创建互斥体
等待单个对象
释放互斥锁
关闭手柄
这些是 CMutex 封装的底层 Win32 API 调用。
对于仅进程内的互斥锁,您还可以使用这些调用,它们更快:
InitializeCriticalSection EnterCriticalSection 离开关键部分 删除关键部分
InitializeCriticalSection
EnterCriticalSection
离开关键部分
删除关键部分
以下功能可能是您想要的,它们都记录在 MSDN 上。
CreateMutex(...) WaitForSingleObject(...) ReleaseMutex(...)