answersLogoWhite

0


Best Answer

A handle is a reference for the operating system. It does not have the semantics of a programming reference but what it does do is allow the system resources to know what you are referring to when it is passed in an API call. Usually, the HANDLE is wrapped in an instance of a class. CWnd is a good example, it contains an HWND which is a handle to a window. You can do this. CWnd *pWnd = CWnd::FromHandle(hWnd) Note: that CWnd::FromHandle(hWnd) is static and does not require an instance. It will pass you back the wrapper that the hWnd is wrapped by. Well not quite! If the handle is not actually wrapped by an object it will create one AND IT WILL ONLY BE TEMPORARY.So use it the once then throw it away. It can create the instance because the hWnd has enough information in its struct for windows to instantiate a CWnd object. It does not add it to the handle v object table, so it is only temporary. The HWND is in fact a kernel object and theres more ? HWND (CWnd and CWnd-derived classes) HDC (CDC and CDC-derived classes) HMENU (CMenu) HPEN (CGdiObject) HBRUSH (CGdiObject) HFONT (CGdiObject) HBITMAP (CGdiObject) HPALETTE (CGdiObject) HRGN (CGdiObject) HIMAGELIST (CImageList) SOCKET (CSocket) (Should have been HSOCKET?) + others. I am not sure if all of these would pass back a temporary object if required. ::GetDC(hWnd) will get you a hDC from an hWnd but it will be temporary, probably better to use the CDC claa. It may be a fundamental requirement for windows programming? For a proper explanation look up Google with this "Inside MFC: Handle Maps and Temporary Objects"

User Avatar

Wiki User

18y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

11y ago

Generally speaking, a handle is an abstract reference to a resource that is managed by another system, such as the operating system or a database. Normally we use pointers to reference objects in memory, but the objects we point at are under our direct control; they do not arbitrarily relocate themselves without us knowing about it. But resources outwith our direct control have a nasty habit of moving around in memory behind our backs, which would be disastrous if we simply pointed at them (our pointers would constantly be invalidated).

By using a handle, the resources can freely move around as required by the external system that controls them without invalidating the handle. Implementations vary but a handle is often implemented as a key or index into a table of resources which map the handle to an actual memory address. Thus when we pass a handle into an API that understands the handle's purpose, the handle can be dereferenced accordingly.

For instance, when we call various functions in the Windows Win32 API, we might pass an HWND value which is a handle to a specific window, or an HKEY value which is a handle to a specific registry key, or an HFILE which is a handle to a disk file. We use these same APIs to initialise the handles and, if required, release them when they are no longer required. We cannot predict where these objects will reside in memory at any given moment, but with a handle we don't have to because the system that controls those resources can use the handle to locate them for us, via the API provided by that system.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is a handle in Windows Programming?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is the difference between windows programming and .Net programming?

Windows programming is a general term for writing programs intended for the Windows platforms. We can write Windows programs in any programming language. The .NET framework is specifically intended to be used with C#, F# and Visual Basic programming languages.


Where can you learn about Windows Programming?

You can learn about Windows programming by looking into the Windows registry. Here is the place where all the programs are stored. To effectively get started with Windows programming, there are online manuals that can be looked at an read to get the person on the right track.


Which windows is best for programming Windows xp or Windows 98?

XP


How do you do C programming on your Windows?

C programming can be started on Windows by using a suitable IDE (these include compilers) such as Dev-C++


What is the message structure in windows programming?

No.


Where may a person find information about Windows XP programming updates?

To find out about Windows XP programming updates you will need to visit the Microsoft Windows website. There are many other independent sites with information relating to Windows XP programming updates such as dummies and ehow.


In c programming or gml what does hwnd mean?

If your using Windows, its the API call for a window. It stands for (h) handle (Wnd) Window. Its the standard call all other commands use to gain access to a window. Microsoft likes to prefix their variables with the lowercase letter h to represent a 'handle' to that object. For instance, an hDC is a handle to a device context. If you've done any programming using the Windows API, you will encounter many such syntactical conventions. You can reference any given window through its hWnd handle. http://www.blitzbasic.com/Community/posts.php?topic=55029


Where can one find an expert in Windows programming?

One can find an expert in Windows programming through online programmer websites such as CodeGuru Forums and INTJ Forum. One can also find Windows programming experts working at colleges and technical schools.


What is the difference between aspnet vbnet and c?

asp.net is website programming vb.net is windows forms programming the visual basic language c#.net is windows forms programming in c# language


What is an Ioctl in windows programming?

there is no IOCTL in windows programming. You will find device control methods for windows in the following pagehttp://msdn.microsoft.com/en-us/library/aa363219%28VS.85%29.aspx


Describe windows programming architecture?

which is not known by anyone


Why using programming languages?

to make windows applications