网站首页  词典首页

请输入您要查询的函数:

 

术语 openmutex
释义 OpenMutex
语法:
C++
HANDLE WINAPI OpenMutex(
__in DWORD dwDesiredAccess,
__in BOOL bInheritHandle,
__in LPCTSTR lpName
);
OpenMutex函数
打开一个现有的命名互斥对象。
参数
dwDesiredAccess [in]
到互斥对象访问。只有同步探视权,需要使用互斥,改变互斥的安全,指定MUTEX_ALL_ACCESS。函数失败如果指定对象的安全描述符不允许为调用进程的请求的访问。如需使用权名单,见同步对象的安全和访问权限。
bInheritHandle [in]
如果该值为TRUE,进程创建的这一进程将继承处理。否则,该进程不会继承此处理。
lpName [in]
互斥的名字被打开。名称比较是区分大小写的。
这个函数可以打开一个私人空间的对象。有关更多信息,请参见对象命名。
终端服务:名称可以有一个“全球\\”或“Local \\”前缀显式打开一个对象,在全球或会话名称空间。名称的其余部分可以包含以外的任何字符反斜杠字符(\\)。如需信息见命名内核对象。
Windows XP家庭版:快速用户切换是使用终端服务会话。第一个用户对使用记录会话0,下一个用户登录使用会话1,依此类推。内核对象名称必须遵循概述了终端服务,使应用程序能够支持多个用户的指导方针。
窗口2000:如果终端服务没有运行,“全球\\”和“地方\\”前缀将被忽略。名称的其余部分可以包含反斜杠以外的任何字符的字符。
返回值
如果函数成功,返回值是一个句柄互斥对象。
如果函数失败,返回值为NULL。为了获得更多错误信息,调用GetLastError。
If a named mutex does not exist, the function fails and GetLastError returns ERROR_FILE_NOT_FOUND.
备注
该OpenMutex功能允许多个进程打开同一互斥对象句柄。函数调用成功,只有一些进程已经创建使用CreateMutex函数的互斥。调用进程可以使用返回的任何处理函数,需要一个句柄互斥对象,如等待功能,但须在指定dwDesiredAccess参数的准入限制。
句柄可以通过使用DuplicateHandle函数重复。使用CloseHandle函数关闭处理。该系统关闭时自动处理过程终止。互斥量对象被销毁时,其最后处理已关闭。
如果您的多线程应用程序必须反复创建,打开和关闭一个已命名的互斥对象,竞争状态可能会发生。在这种情况下,最好使用CreateMutex而不是OpenMutex,因为CreateMutex打开一个互斥如果它存在,并创建,如果事实并非如此。
实例
举一个例子,它使用OpenMutex,请参阅使用命名对象。
要求:
最低支持:client-Windows 2000专业版
最低支持server-Windows 2000服务器
HeaderWinbase.h(头文件:winuser.h)
LibraryKernel32.lib
DLLKernel32.dll
Unicode和ANSI namesOpenMutexW(Unicode)和OpenMutexA(ANSI)的
参见
CloseHandle
CreateMutex
CreateProcess的
DuplicateHandle
互斥对象
对象名称
ReleaseMutex
同步功能
如果有任何问题和意见,请发送给微软(wsddocfb@microsoft.com)
生成日期:2009年8月27日
==英文原文==OpenMutex Function
Opens an existing named mutex object.
Syntax
C++
HANDLE WINAPI OpenMutex(
__in DWORD dwDesiredAccess,
__in BOOL bInheritHandle,
__in LPCTSTR lpName
);
Parameters
dwDesiredAccess [in]
The access to the mutex object. Only the SYNCHRONIZE access right is required to use a mutex; to change the mutex's security, specify MUTEX_ALL_ACCESS. The function fails if the security descriptor of the specified object does not permit the requested access for the calling process. For a list of access rights, see Synchronization Object Security and Access Rights .
bInheritHandle [in]
If this value is TRUE, processes created by this process will inherit the handle. Otherwise, the processes do not inherit this handle.
lpName [in]
The name of the mutex to be opened. Name comparisons are case sensitive.
This function can open objects in a private namespace. For more information, see Object Namespaces .
Terminal Services: The name can have a "Global\\" or "Local\\" prefix to explicitly open an object in the global or session name space. The remainder of the name can contain any character except the backslash character (\\). For more information, see Kernel Object Namespaces .
Windows XP Home Edition: Fast user switching is implemented using Terminal Services sessions. The first user to log on uses session 0, the next user to log on uses session 1, and so on. Kernel object names must follow the guidelines outlined for Terminal Services so that applications can support multiple users.
Windows 2000: If Terminal Services is not running, the "Global\\" and "Local\\" prefixes are ignored. The remainder of the name can contain any character except the backslash character.
Return Value
If the function succeeds, the return value is a handle to the mutex object.
If the function fails, the return value is NULL. To get extended error information, call GetLastError .
If a named mutex does not exist, the function fails and GetLastError returns ERROR_FILE_NOT_FOUND.
Remarks
The OpenMutex function enables multiple processes to open handles of the same mutex object. The function succeeds only if some process has already created the mutex by using the CreateMutex function. The calling process can use the returned handle in any function that requires a handle to a mutex object, such as the wait functions , subject to the limitations of the access specified in the dwDesiredAccess parameter.
The handle can be duplicated by using the DuplicateHandle function. Use the CloseHandle function to close the handle. The system closes the handle automatically when the process terminates. The mutex object is destroyed when its last handle has been closed.
If your multi-threaded application must repeatedly create, open, and close a named mutex object, a race condition can occur. In this situation, it is better to use CreateMutex instead of OpenMutex, because CreateMutex opens a mutex if it exists and creates it if it does not.
Examples
For an example that uses OpenMutex, see Using Named Objects .
Requirements
Minimum supported clientWindows 2000 Professional
Minimum supported serverWindows 2000 Server
HeaderWinbase.h (include Windows.h)
LibraryKernel32.lib
DLLKernel32.dll
Unicode and ANSI namesOpenMutexW (Unicode) and OpenMutexA (ANSI)
See Also
CloseHandle
CreateMutex
CreateProcess
DuplicateHandle
Mutex Objects
Object Names
ReleaseMutex
Synchronization Functions
Send comments about this topic to Microsoft
Build date: 8/27/2009
==原始网址==http://msdn.microsoft.com/en-us/library/ms684315(VS.85).aspx\n
随便看

 

windows api函数参考手册包含2258条windows api函数文档,详细介绍nodejs、java、rust调用windows api的方法技巧,是学习windows api编程的入门中文文档。

 

Copyright © 2004-2023 Winrtm.com All Rights Reserved
京ICP备2021023879号-40 更新时间:2024/10/6 13:17:29