网站首页  词典首页

请输入您要查询的函数:

 

术语 createmutexex
释义 CreateMutexEx
语法:
C++
HANDLE WINAPI CreateMutexEx(
__in_opt LPSECURITY_ATTRIBUTES lpMutexAttributes,
__in_opt LPCTSTR lpName,
__in DWORD dwFlags,
__in DWORD dwDesiredAccess
);
CreateMutexEx功能
创建或打开一个有名或无名的互斥对象,并返回的句柄对象。
参数
lpMutexAttributes [中,可选]
一个SECURITY_ATTRIBUTES结构的指针。如果该参数为NULL,则互斥句柄不能被继承的子进程。
结构的lpSecurityDescriptor成员指定一个新的mutex安全描述符。如果lpMutexAttributes为NULL,则互斥得到默认的安全描述。在对来自互斥默认安全描述符的ACL或模拟的主要创造者的象征。有关更多信息,请参阅同步对象的安全和访问权限。
lpName [中,可选]
该互斥对象的名称。该名称被限制为MAX_PATH字符。名称比较是区分大小写的。
如果lpName为NULL,则互斥对象创建没有名称。
如果lpName匹配现有的事件,信号量,可等待定时器,工作,或文件映射对象,该函数失败,而且GetLastError函数返回出现ERROR_INVALID_HANDLE名。这是因为这些对象共享相同的名称空间。
这个名称可以有一个“全球\\”或“Local \\”前缀明确创建对象的全球或会话名称空间。名称的其余部分可以包含以外的任何字符反斜杠字符(\\)。如需信息见命名内核对象。快速用户切换是使用终端服务会话。内核对象名称必须遵循概述了终端服务,使应用程序能够支持多个用户的指导方针。
该对象可以创建一个私人空间。有关更多信息,请参见对象命名。
dwFlags [in]
此参数可以是0或下面的值。
ValueMeaning
CREATE_MUTEX_INITIAL_OWNER
0x00000001The对象的创建者是互斥最初所有者。
dwDesiredAccess [in]
为互斥对象访问掩码。如需使用权名单,见同步对象的安全和访问权限。
返回值
如果函数成功,返回值是一个句柄到新创建的互斥对象。
如果函数失败,返回值为NULL。为了获得更多错误信息,调用GetLastError。
如果锁是一个名为互斥和对象调用此函数之前存在,返回值是一个句柄现有的对象,GetLastError返回ERROR_ALREADY_EXISTS,bInitialOwner被忽略,调用线程不获批准的所有权。但是,如果调用了有限的访问权限,该函数将失败,ERROR_ACCESS_DENIED和调用应该使用OpenMutex函数。
备注
如果您使用命名互斥限制您的应用程序单实例,恶意用户可以创建此互斥量在此之前,防止启动您的应用程序。为了防止这种情况下,创建一个随机命名的互斥和存储名称,以便它只能由授权用户获得的。此外,还可以用于此目的的文件。为了限制您的应用程序每个用户实例,创建一个用户配置文件目录锁定的文件。
任何调用进程的线程可以指定互斥对象在调用句柄在等待职能之一。单对象等待函数返回时,指定对象的状态信号。在多对象等待函数可以奉命返回或者当任何一个或指定对象的所有信号。当一个等待函数返回时,等待线程被释放继续执行。
一个互斥对象的状态时,信号没有任何线程拥有。在创建线程可以使用dwFlags参数要求的互斥立即拥有。否则,一个线程必须使用等待函数请求权之一。当互斥的状态信号,一个等待线程被授予权,是互斥的状态更改为无信号,并等待函数返回。只有一个线程可以拥有在任何时间互斥。所属线程使用ReleaseMutex函数来释放它的所有权。
线程拥有互斥可以指定重复等待功能相同的互斥体通话过程中不会阻止其执行。通常情况下,您不会一再等待相同的互斥体,但这一机制本身防止死锁而互斥体,它已经拥有等待一个线程。然而,释放其所有权,该线程必须要求每次ReleaseMutex一次满意的互斥等待。
两个或多个进程可以调用CreateMutex创建相同的命名互斥。第一个进程实际创建互斥量,并有足够的访问权限只需打开一个句柄现有互斥事后处理。这使得多个进程得到相同的互斥处理,同时,减轻责任确保用户创建进程启动第一。当使用这种方法,您不应该使用CREATE_MUTEX_INITIAL_OWNER标志,否则,可能难以肯定的进程已经初步所有权。
多个进程可以有相同的互斥对象句柄,使使用的进程间同步对象。下列对象共享机制可用:
子进程的CreateProcess函数创建可以继承的句柄互斥对象如果CreateMutex lpMutexAttributes参数启用继承。这种机制为有名和无名互斥。
一个进程可以指定处理的互斥对象在调用DuplicateHandle函数来创建一个重复的句柄可以被另一个进程使用。这种机制为有名和无名互斥。
一个进程可以调用指定命名互斥的OpenMutex或CreateMutex函数检索的句柄互斥对象。
使用CloseHandle函数关闭处理。该系统关闭时自动处理过程终止。互斥量对象被销毁时,其最后处理已关闭。
要求:
client最低支持Vista
server最低支持 Windows Server 2008
HeaderWinbase.h(头文件:winuser.h)
LibraryKernel32.lib
DLLKernel32.dll
Unicode和ANSI namesCreateMutexExW(Unicode)和CreateMutexExA(ANSI)的
参见
CloseHandle
互斥对象
同步功能
如果有任何问题和意见,请发送给微软(wsddocfb@microsoft.com)
生成日期:2009年8月27日
==英文原文==CreateMutexEx Function
Creates or opens a named or unnamed mutex object and returns a handle to the object.
Syntax
C++
HANDLE WINAPI CreateMutexEx(
__in_opt LPSECURITY_ATTRIBUTES lpMutexAttributes,
__in_opt LPCTSTR lpName,
__in DWORD dwFlags,
__in DWORD dwDesiredAccess
);
Parameters
lpMutexAttributes [in, optional]
A pointer to a SECURITY_ATTRIBUTES structure. If this parameter is NULL, the mutex handle cannot be inherited by child processes.
The lpSecurityDescriptor member of the structure specifies a security descriptor for the new mutex. If lpMutexAttributes is NULL, the mutex gets a default security descriptor. The ACLs in the default security descriptor for a mutex come from the primary or impersonation token of the creator. For more information, see Synchronization Object Security and Access Rights .
lpName [in, optional]
The name of the mutex object. The name is limited to MAX_PATH characters. Name comparison is case sensitive.
If lpName is NULL, the mutex object is created without a name.
If lpName matches the name of an existing event, semaphore, waitable timer, job, or file-mapping object, the function fails and the GetLastError function returns ERROR_INVALID_HANDLE. This occurs because these objects share the same name space.
The name can have a "Global\\" or "Local\\" prefix to explicitly create the 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 . Fast user switching is implemented using Terminal Services sessions. Kernel object names must follow the guidelines outlined for Terminal Services so that applications can support multiple users.
The object can be created in a private namespace. For more information, see Object Namespaces .
dwFlags [in]
This parameter can be 0 or the following value.
ValueMeaning
CREATE_MUTEX_INITIAL_OWNER
0x00000001The object creator is the initial owner of the mutex.

dwDesiredAccess [in]
The access mask for the mutex object. For a list of access rights, see Synchronization Object Security and Access Rights .
Return Value
If the function succeeds, the return value is a handle to the newly created mutex object.
If the function fails, the return value is NULL. To get extended error information, call GetLastError.
If the mutex is a named mutex and the object existed before this function call, the return value is a handle to the existing object, GetLastError returns ERROR_ALREADY_EXISTS, bInitialOwner is ignored, and the calling thread is not granted ownership. However, if the caller has limited access rights, the function will fail with ERROR_ACCESS_DENIED and the caller should use the OpenMutex function.
Remarks
If you are using a named mutex to limit your application to a single instance, a malicious user can create this mutex before you do and prevent your application from starting. To prevent this situation, create a randomly named mutex and store the name so that it can only be obtained by an authorized user. Alternatively, you can use a file for this purpose. To limit your application to one instance per user, create a locked file in the user's profile directory.
Any thread of the calling process can specify the mutex-object handle in a call to one of the wait functions . The single-object wait functions return when the state of the specified object is signaled. The multiple-object wait functions can be instructed to return either when any one or when all of the specified objects are signaled. When a wait function returns, the waiting thread is released to continue its execution.
The state of a mutex object is signaled when it is not owned by any thread. The creating thread can use the dwFlags parameter to request immediate ownership of the mutex. Otherwise, a thread must use one of the wait functions to request ownership. When the mutex's state is signaled, one waiting thread is granted ownership, the mutex's state changes to nonsignaled, and the wait function returns. Only one thread can own a mutex at any given time. The owning thread uses the ReleaseMutex function to release its ownership.
The thread that owns a mutex can specify the same mutex in repeated wait function calls without blocking its execution. Typically, you would not wait repeatedly for the same mutex, but this mechanism prevents a thread from deadlocking itself while waiting for a mutex that it already owns. However, to release its ownership, the thread must call ReleaseMutex once for each time that the mutex satisfied a wait.
Two or more processes can call CreateMutex to create the same named mutex. The first process actually creates the mutex, and subsequent processes with sufficient access rights simply open a handle to the existing mutex. This enables multiple processes to get handles of the same mutex, while relieving the user of the responsibility of ensuring that the creating process is started first. When using this technique, you should not use the CREATE_MUTEX_INITIAL_OWNER flag; otherwise, it can be difficult to be certain which process has initial ownership.
Multiple processes can have handles of the same mutex object, enabling use of the object for interprocess synchronization. The following object-sharing mechanisms are available:
A child process created by the CreateProcess function can inherit a handle to a mutex object if the lpMutexAttributes parameter of CreateMutex enabled inheritance. This mechanism works for both named and unnamed mutexes.
A process can specify the handle to a mutex object in a call to the DuplicateHandle function to create a duplicate handle that can be used by another process. This mechanism works for both named and unnamed mutexes.
A process can specify a named mutex in a call to the OpenMutex or CreateMutex function to retrieve a handle to the mutex object.
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.
Requirements
Minimum supported clientWindows Vista
Minimum supported serverWindows Server 2008
HeaderWinbase.h (include Windows.h)
LibraryKernel32.lib
DLLKernel32.dll
Unicode and ANSI namesCreateMutexExW (Unicode) and CreateMutexExA (ANSI)
See Also
CloseHandle
Mutex Objects
Synchronization Functions
Send comments about this topic to Microsoft
Build date: 8/27/2009
==原始网址==http://msdn.microsoft.com/en-us/library/ms682418(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:20:08