Platform SDK: DLLs, Processes, and Threads

Object Names

Named objects provide an easy way for processes to share object handles. Once a process has created a named event, mutex, semaphore, or timer object, other processes can use the name to call the appropriate function (OpenEvent, OpenMutex, OpenSemaphore, or OpenWaitableTimer) to open a handle to the object. Name comparison is case sensitive.

The names of event, semaphore, mutex, waitable timer, file-mapping, and job objects share the same name space. If you try to create an object using a name that is in use by an object of another type, the function fails and GetLastError returns ERROR_INVALID_HANDLE. Therefore, when creating named objects, use unique names and be sure to check function return values for duplicate-name errors.

If you try to create an object using a name that is in use by an object of same type, the function succeeds, returning a handle to the existing object, and GetLastError returns ERROR_ALREADY_EXISTS. For example, if the name specified in a call to the CreateMutex function matches the name of an existing mutex object, the function returns a handle to the existing object. In this case, the call to CreateMutex is equivalent to a call to the OpenMutex function. Having multiple processes use CreateMutex for the same mutex is therefore equivalent to having one process that calls CreateMutex while the other processes call OpenMutex, except that it eliminates the need to ensure that the creating process is started first. When using this technique for mutex objects, however, none of the calling processes should request immediate ownership of the mutex. If multiple processes do request immediate ownership, it can be difficult to predict which process actually gets the initial ownership.

Terminal Services: A Terminal Services environment has a global name space for events, semaphores, mutexes, waitable timers, file-mapping objects, and job objects. In addition, each Terminal Services client session has its own separate name space for these objects. Terminal Services client processes can use object names with a "Global\" or "Local\" prefix to explicitly create an object in the global or session name space. For more information, see Kernel Object Name Spaces.

Windows 2000: On Windows 2000 systems without Terminal Services running, the "Global\" and "Local\" prefixes are ignored. The names of events, semaphores, mutexes, waitable timers, file-mapping objects, and job objects share the same name space.

Windows NT 4.0 and earlier, Windows 95/98: The names of events, semaphores, mutexes, waitable timers, and file-mapping objects share the same name space. The functions for creating or opening these objects fail if you specify a name containing the backslash character (\).