ManuelSchneid3r
ManuelSchneid3r

Reputation: 16091

Is a const HANDLE really const?

As far is I learned a HANDLE is just a number referring to some kind of "sytem ressource table". Is this handle const correct? I guess not because it is just used to access a table like an index on an array. An example with bitmaps: Can I change the content of a bitmap althought the HBITMAP is declared const?

Upvotes: 1

Views: 1289

Answers (1)

Eli Algranti
Eli Algranti

Reputation: 9007

HANDLE is (AFAIR) a typedef of int so const HBITMAP is the same as const int.

In this sense you can change the contents of the bitmap even if handle to the bitmap is const because const refers to the handle not the actual bitmap (think of it as a const pointer to a variable class.)

BUT:

Your question is moot anyway because:

  • Handles are a feature of the Win32 API which is a C api not a C++ (and created before C gained const).
  • You cannot change bitmaps (or any other "object" represented by a handle) directly anyway. The handle is an opaque reference to Win32 structures and can be manipulated only through the appropriate Win32 API calls used to handle (no pun intended) the "object".

I place "object" in quotes because Handles refer to conceptual objects (software representations of concepts) not actual C++ objects, again because Win32 is a C API.

Upvotes: 3

Related Questions