Handler? What is this and what is it for in C/C++?

Asked

Viewed 2,674 times

2

For a long time I’ve seen many code using this type HANDLER. What is it and what is it for? Where I find tutorials that teach you how to use it.

  • 2

    It would be a good example of code. HANDLE != HANDLER, are related but distinct things.

2 answers

4

There are no tutorials on this and it’s not even our goal.

The question talks in HANDLER, which does not seem to be the case. The context indicates you want to know about the type HANDLE or the concept of Handle, which is different from Handler.

HANDLE is not a type of C or C++, is from API Windows. This type is just a pointer to void, that is, it could be anything. But this is implementation detail. Almost all types that start with H in that documentation sane Handles.

There are several different manipulation objects. Not all have this name. A FP C standard (for manipulating files) is still a Handle. The HWND is one of the most used windows by taking care of the window.

The concept of Handle is more generic. It is an object that stores relevant information for access to an external resource. It indicates what the resource is (an operating system or service identifier or a pointer).

A Handler is the agent who will use an object, who will do some required action, in general programming is your code written for the purpose of executing something on top of a Handle.

1


HANDLE can be anything from an integer index to a pointer to a resource in kernel space. The idea is that they provide an abstraction of a resource, so you don’t need to know much about the resource itself to use it.

For example, the HWND in the Win32 API is a HANDLE type for a window. By itself, it is useless: you cannot collect any information from it. But move on to the correct API functions, and you can perform a number of different tricks with it. Internally, you can think of HWND as just an index in the GUI window table (which may not be how it’s implemented, but makes magic make sense).

  • 1

    Only a small observation of HWND terminology is HANDLE and not HANDLER. Handle is the reference (the "knob" from which you take the object) - Handler is the handler. Example of Handler: something that meets a specific protocol, such as skype when dealing with a URL like this: skype://nameplate - Example of Handle: HWND window.... file = fopen( .... etc

Browser other questions tagged

You are not signed in. Login or sign up in order to post.