News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

what is a handle

Started by loki_dre, April 17, 2008, 03:55:53 PM

Previous topic - Next topic

loki_dre

what exactly does a HANDLE represent?
ie. in the code :

        hMemory     HANDLE  ?
        pMemory     DWORD   ?

        ;ALLOCATE AND LOCK OUR MEMORY
        invoke GlobalAlloc, GMEM_MOVEABLE or GMEM_ZEROINIT, MEMORYSIZE
        mov hMemory, eax
        invoke GlobalLock, hMemory
        mov pMemory, eax

hutch--

loki,

Almost exclusively all identifiers in win32 are DWORD in size. Handles, pointers and almost all of the equated data types commonly used in C reference material. Look at the beginning of the windows.inc file to see the bulk of the equates.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Bill Cravener

A HANDLE is what I hold on to when I drink coffee from my cup in the morning. Just kidding you loki. :bg

I would add to what Steve stated above that inside the kernel Windows maintains a table of all the different objects that the kernel is responsible for. Windows buttons, icons, mouse pointers, etc, they all get an entry in the table and each entry is assigned a unique identifier known as a HANDLE.



My MASM32 Examples.

"Prejudice does not arise from low intelligence it arises from conservative ideals to which people of low intelligence are drawn." ~ Isaidthat

loki_dre

How can I get the actual object data from the handle???? does the method used to access the data depend on the handle or is there one particular function I can call to get the data?

hutch--

Loki,

The handle is the identifier of the object, what you must do is learn the functions that use the identifier and there are many of them.

GetWindowText() = Get the text from a specif9ed window identified by its handle.
SendMessage() = Send a message to a window with a specified handle.

With a bitmap handle you call the appropriate function using that handle and for information on the bitmap you read the bitmap header.

Sometimes when you allocate memory the value you get back is BOTH the handle for the memory AND the start address.

Think of a handle as how you identify something when you use any of a large number of functions in Windows.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

ic2

I always wonder if I was right to  consider dialogs, buttons, bitmaps, icons, etc as objects but can data be a object and if so what make data be consider as an  object?  Is it simply the handle for the text?

When I see the word object I never really pay it no attention because I did know it it was c related.

u

#6
A pointer to some data in memory, or a handle to a pointer to memory, with a set of API functions that can be used on it, is an object.
A Win32 HANDLE/HWND/HBITMAP... is the ID of a Win32 system-object. It basically usually hides the pointer to the underlying data. Reasons for hiding the pointer from the programmer are :
1) sometimes for cross-process availability, especially HWND handles - it's much-easier to manage by ID than doing complex virtual-memory mapping tricks (to provide the same pointer validity across the system) ;
2) sometimes it's not nice to have direct access to the data;
3) sometimes Win32 can reallocate the object (old pointer becomes invalid) ;
4) for some types of objects, some operations could be made faster if referencing by ID.

Btw, HMODULE is obviously a pointer, though :) .


Some handles are available accross processes, others are not.
Please use a smaller graphic in your signature.

ic2

A Win32 HANDLE is the ID of a Win32 system-object ( hope it's not mines)

Ultrano I bet I would have to read three chapters for what you just describe in such few words.   That is sooo complicate.  I am glad I try ASM.  At first site ASM was 1000x more crazy but that stuff is worse.  I don't even know what to say...  I just hope i did not come across any of that while using masm32 all this time.

Never HW.   Anyway I'm going to school now (at Computer Concepts VB pages and I don't see it) and the way they got things set up I'll be force to study that stuff.  It may be years before I get to the parts I like. This is crazy.   I'll just keep this page open for a few day and let it slowly sink in.


Thank you very much Ultrano

hutch--

try and keep this in mind, an "object" is an abstract concept where a handle is at its simplest, a unique number the operating system uses to identify a vast range of things. The reason for include file equates is so the numbers are easier to identify and alternatively easier to use in code that you write. A button is a button whether you code it at the lowest level in MASM or the highest level of OOP style programming and it is purely how you describe it as to whether it is spoken of as an "object", a "control", an "os" function.

Where a "handle" is only ever a unique ID for something maintained by the operating system, an "object"is almost exclusively a complex block of code that performs a much higher level function and in the context of such a higher level function, it is in some circumstances convenient to describe it as an "object" among many other objects.

Now if you choose to describe a control like an edit control as an "object", you in fact IDENTIFY that object by its HANDLE.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php