Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Seriema

Win32, passing a HANDLE?

This topic is 5675 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hello! I''m passing a handle around. It''s the window handle. cGraphicsCore must create a window for it. Then audio and keyboard can access it. cGraphicsCore::Initiate(m_hWnd, m_hInst) ); cAudioCore::Initiate(m_hWnd) ); cInputCore::Initiate() ); cICKeyboard::Initiate(m_hWnd) ); But inside cGraphicsCore I''m doing this: cGC_hWnd = parameter_hWnd; do stuff to cGC_hWnd. but I want to parameter_hWnd to be affected to! I thought HANDLES worked like pointers? "No lies of sugar can sweeten the sournes of reality" }+TITANIUM+{ A.K.A. DXnewbie[onMIRC]

Share this post


Link to post
Share on other sites
Advertisement
quote:
Original post by ZealousElixir
Handles are structs containing a single 32-bit value, so passing them by address has no benefit.


actually, handles are pointers to such structs.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:
Original post by niyaw
[quote]Original post by ZealousElixir
Handles are structs containing a single 32-bit value, so passing them by address has no benefit.


actually, handles are pointers to such structs.
A HANDLE is only a number in a usermode process, that identifies a kernel object once a thread in the application does a transition to kernel mode.

I believe handle is defined as "void*", but that doesn''t make it a pointer.

Share this post


Link to post
Share on other sites
oki I''ll try again.

I have a cApplication, it contains a HWND as a member. Another class, cGraphicsCore, sets up the actual window. Other classes like cAudioCore and cInputCore require the window to be up and running. That''s why I call cGraphicsCore first, passing the cApplication::HWND as a parameter in cGraphicsCore::Initiate(). Although the window sets up alright and all, the cApplication::HWND doesn''t seem to "HANDLE" it

I tried taking in a HWND*, and it worked. But somehow it doesn''t feel right...

Did this not work because HWND didn''t HANDLE a window from start? If cApplication created the window, then passing the HWND would do the same as sending a pointer. Right?.. :/

"No lies of sugar can sweeten the sournes of reality"

}+TITANIUM+{ A.K.A. DXnewbie[onMIRC]

Share this post


Link to post
Share on other sites
quote:
Original post by Anonymous Poster
A HANDLE is only a number in a usermode process, that identifies a kernel object once a thread in the application does a transition to kernel mode.


a handle can be an opaque pointer, and they don''t have to originate in kernel.
quote:

I believe handle is defined as "void*", but that doesn''t make it a pointer.

handle is often defined as a pointer to a struct containing a single dummy integer value, to prevent assignments such as

HWND hwnd = ...;
HDC hdc = hwnd;

which is what i said earlier. the "generic" handle is a void pointer, and while this definition is easy to use it also leaves a chance of passing a particular handle to functions that don''t work with that handle''s type.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
This thread is painful to read . Everyone repeat after me: A HANDLE IS NOT A POINTER. I repeat, A HANDLE IS NOT A POINTER.

The exact meaning of "handle" seems to vary greatly from one platform to another so some confusion has arisen. In the Windows world, a handle is simply a value that is used as an identifier. As an application programmer, you should not assume that a handle is anything beyond some number used internally by the system.

For example, if you view the value of kernel handles (such as the handle returned by CreateFile), you''ll see that these are low numbers -- definitely not valid pointers.

Some handles are pointers. For example, if you call LoadLibrary, the resulting HMODULE is a pointer to the location in the application''s memory space that the DLL has been loaded. However, you should not rely on this. As far as I know, it''s undocumented and subject to change in future versions.

That being said, HANDLE is declared as a void* in the Windows headers. Under 32-bit Windows, handles could be represented in the API as unsigned longs without any ill effect. I''m assuming void* is used either for historical reasons or to allow HANDLE to be polymorphic with the stricter handle types or to allow handle size to be equivalent to pointer size.

Seriema, the practical benefit of this to you is that you should not view handles as being just like pointers. View them simply as some value that means something to Windows. Treat them as you would an int, not as you would (normally) treat a pointer.

Where are you creating the HWND? In cGraphicsCore Initiate or before?

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!