A very simple question, if i create a HANDLE
in app1.exe and it gets value 0x01
is that value globally unique ?
Or is it possible that when some other process creates a HANDLE
that also has value 0x01
.
If they are not unique what other construct can i use to get a unique id compatible with handles (such that it will be impossible or highly unlikely that a HANDLE
with that id is created anywhere else).
Properly, in Windows, (and generally in computing) a handle is an abstraction which hides a real memory address from the API user, allowing the system to reorganize physical memory transparently to the program. Resolving a handle into a pointer locks the memory, and releasing the handle invalidates the pointer.
The handle wrapping functions of the MFC class library let you find the C++ object that is wrapping the Windows object that has a particular handle. However, sometimes an object does not have a C++ wrapper object and at these times the system creates a temporary object to act as the C++ wrapper.
In one of the rare cases where Windows sets a hard-coded upper limit on a resource, the Executive defines 16,777,216 (16*1024*1024) as the maximum number of handles a process can allocate.
In computer programming, a handle is an abstract reference to a resource that is used when application software references blocks of memory or objects that are managed by another system like a database or an operating system.
The important thing to understand is that handles are not objects. Handles are pointers (or indexes) to per-process object table. To answer your question, HANDLES are not globally unique, but they are scoped to only make sense inside a particular process.
For any kernel object to be able to be accessible from other process, you have to DuplicateHandle.
Another way to share objects across processes is to call CreateProcess with bInheritHandles set to true.
They are not unique. HANDLE
values are local to the current process. Same value may be invalid handle or refer to a different object in another process. An exception to this rule are handles inherited from parent process.
The only way to have unique id without a centralized registry is to use GUID
. But they are not compatible with HANDLE, they are 128-bit while handles are 32 or 64-bit.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With