Are winapi global?

A very simple question: if I create a HANDLE in the app1.exe file and get the value 0x01 , is this value globally unique?

Or it is possible that when some other process creates a HANDLE , which also has a value of 0x01 .

If they are not unique, then what other constructor can I use to get a unique identifier that is compatible with descriptors (such that it will be impossible or unlikely that a HANDLE with this identifier is created elsewhere).

+6
source share
3 answers

It is important to understand that descriptors are not objects. Pens are pointers (or indexes) for each table of objects. To answer your question, HANDLES are not globally unique, but they are limited to make sense only in a specific process.

In order for any kernel object to be accessible from another process, you must DuplicateHandle .

Another way to share objects between processes is to call CreateProcess with bInheritHandles set to true.

+5
source

Use the DuplicateHandle to pass descriptors between processes.

+2
source

They are not unique. HANDLE values ​​are local to the current process. The same value may be an invalid handle or refer to another object in another process. Exceptions to this rule are descriptors inherited from the parent process.

The only way to have a unique identifier without a central registry is to use a GUID . But they are not compatible with HANDLE, they are 128-bit, and descriptors are 32 or 64-bit.

+2
source

Source: https://habr.com/ru/post/911442/


All Articles