+ 2
What is a HANDLE variable in C++?
Whats a HANDLE variation in C++? Explain with examples please. Thanks!
16 ответов
+ 3
Yes.
+ 6
A Handle is an opaque type. In an OS , it is used to get a reference to an object.
Basically, it is just a key an OS uses to identify all objects contained in it...
Every handle contains a numeric value, which is stored in a large table that the OS uses...
This number is now used to identify the object from the table and change its attributes and properties...
There are several handles for streams, windows, buttons, instances of programs, etc.
These simply help the operating system have a better access to objects, as this process is safer than direct referencing...
Eg:
HANDLE hcout = GetStdHandle(STD_OUTPUT_HANDLE);
//Now, we saved the handle to the output stream in a hcout Handle variable...
//Now we can alter its properties!
SetConsoleTextAttribute(hcout,FOREGROUND_RED);
//Passing our handle to SetConsoleTextAttribute, which helps change color of text in console...
cout<<"Hello World!"<<endl;
//Prints Hello World! in Red!
Similarly, one can create Handles for Custom Windows, Buttons, Files, etc...
There also exist handles for instances, renamed as HINSTANCE...
+ 4
OS = Operating System
Sorry I didn't mention that.
+ 4
Yes. Thats what it is, in a nutshell.
+ 3
The handle returned by the OpenProcess function can be used in any function that requires a handle to a process, such as the wait functions, provided the appropriate access rights were requested.
Most of Windows Functions work with Handles...
+ 3
OpenProcess opens a local Process...
HANDLE WINAPI OpenProcess( _In_ DWORD dwDesiredAccess, _In_ BOOL bInheritHandle, _In_ DWORD dwProcessId );
And returns a handle to it...
+ 2
Thanks!
+ 1
one thing i didnt understand. whats the meaning of OS?
+ 1
and btw. what im actually doing in this line:
HANDLE aa = OpenProcess(PROCESS_ALL_ACESS, FALSE, id);
why is HANDLE necessary here?
+ 1
Ooh i guess i understood. Is it like a "key" to manipulate an specific object in windows? Like a process?
+ 1
So its like a variable that returns a number and i can use this number to manipulate my object, right?
+ 1
thank you very much!
+ 1
I see. So the number returned is like the "process" reference
+ 1
and the handle is the object(process) i can modify right
+ 1
i mean the number returned (HANDLE) by OpenProcess is the object(process) i can modify.
Is that right?
+ 1
Ok. Thank you very much again!! SoloLearn's community is amazing!