I stumbled upon another what I think is initializer, like int and char, named HANDLE.
It's also used when creating an application, I've browsed the net and found that it is a sort of pointer to an object that can change without me knowing it... eh... It wasn't really that good of an explanation. Can anyone explain it a bit more... dumbed down for me? Giving examples usually helps.

int integer;
char character;
HANDLE handle;


  1. What does it do?
  2. How can I use this effectively in a code that doesn't have to do with windows itself? and by that I mean, can I use a handle on one of my own objects or variables or whatever it does?
  3. Can it be used to "point" to a class or a class member? If yes, please give an example

Answer should (doesn't have to) include/have/be:

  • an example
  • explained, if possible, line by line

Sidenote: I've seen this HANDLE used in another code called JASS (Blizz code), where the handle could be a timer, unit, trigger, effect, anything that is an object. If you'd rather explain it through JASS, I won't mind (It's easier to understand Blizz's dumbed down language).
Sidenote: Hope I was clear enough for people to understand. :)

7 Years
Discussion Span
Last Post by ShadowScripter

hm, need more easy to read examples... about this thing, that's what's wrong with most of these things, all they do is blabber on about the most general things, but I have found that it is easier practice to see it in action, much like the cplusplus.com site. I have yet to find an explanation on that site about HANDLEs tho :( (probably blind)


Windows has a table of resources (Windows, buttons, icons, mouse pointers, menus, etc.)
Each resource has an unique ID.
With that ID, you can get that resource, and functions that create a new resource return such an ID.
The simplest example being

  __in      LPCTSTR lpFileName,
  __in      DWORD dwDesiredAccess,
  __in      DWORD dwShareMode,
  __in_opt  LPSECURITY_ATTRIBUTES lpSecurityAttributes,
  __in      DWORD dwCreationDisposition,
  __in      DWORD dwFlagsAndAttributes,
  __in_opt  HANDLE hTemplateFile

Also on http://msdn.microsoft.com/en-us/library/aa363858(VS.85).aspx

This function creates a resource (a file) and gives you its ID, so you can pass that to ReadFile() for example:

  __in         HANDLE hFile,
  __out        LPVOID lpBuffer,
  __in         DWORD nNumberOfBytesToRead,
  __out_opt    LPDWORD lpNumberOfBytesRead,
  __inout_opt  LPOVERLAPPED lpOverlapped

Second param. :)

So, in this case, HANDLE is like C's FILE*: An unique ID for a file.


Ah, this explains alot, I'll bookmark that page, and this page for future reference! Although, I know little about the API, but not enough to understand anything of what you said, apart from the unique ID for the file, which is highly desireable I believe? Cause for this project I'm doing I REALLY need ID's for all the monsters spawned, so that I can then refer back to the specific monster. Altho I guess if you have a static monster, you can just get his location and you're done. So, maybe you can create static objects in windows? :D

This question has already been answered. Start a new discussion instead.
Be sure to adhere to our posting rules.