Get HANDLE to the memory region and what HANDLE actually is

923 views Asked by At
  1. How can i get HANDLE to the memory region or mapped file ?
  2. What actually HANDLE is ?

Please do not answer like this :

A handle is an abstract reference to some resourc,e provided to you by another party (usually the OS), that you can hand back to reference that resource.

I'm interested in technical side

3

There are 3 answers

0
ColdCat On

Handles in windows used to be pointer to a pointer to memory location of an object. In win 3.1 days some program cast some kind of handle to see what's behind. Today to my knowledge this is not possible anymore, they are simple unique identifier or token to communicate between you and the system.
Some more information http://en.wikibooks.org/wiki/Windows_Programming/Handles_and_Data_Types
some more from msdn read paragraph object in 16 bits windows http://msdn.microsoft.com/en-us/library/ms810501.aspx

8
Mike Weir On

A HANDLE is just some arbitrary nugget to some data.

For example, it's returned by the following APIs: CreateFile() and OpenProcess() - as you can tell, these two are very different, yet return the exact same data-type.

Or for memory, you can get access to the heap (which is returned as a HANDLE from GetProcessHeap()) and then use HeapAlloc() against it.

As MSDN points out, it's used in many other contexts:

http://msdn.microsoft.com/en-us/library/windows/apps/ms724211%28v=vs.85%29.aspx

Access token

Communications device

Console input

Console screen buffer

Event

File

File mapping

I/O completion port

Job

Mailslot

Memory resource notification

Mutex

Named pipe

Pipe

Process

Semaphore

Thread

Transaction

Waitable timer

0
Martin Rosenau On

If you do just want to know what it is:

In simple operating systems such handles are really only pointers to a structure in Kernel space. The structure contain more information about the handle itself (e.g. pointer to a file structure). More complex operating systems like Windows will check the validity of a handle before trying to access this structure.

Because the HANDLE is opaque in Windows (this means: Microsoft says: Do not interpret it - it is just a 32-bit number) the actual meaning of a HANDLE may be different in different versions of Windows. Even within one Version (e.g. Vista 32-bit vs. Vista 64-bit or XP SP2 vs XP SP3) the (internal) meaning may be different.

Microsoft may change the meaning anytime they want to change it (it may be a pointer in Windows 95 but an index into an array in Windows 8 - who knows).