Jump to content
  • Advertisement

Archived

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

markdezonia

what is (HWND) really?

This topic is 5202 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

what is (HWND) really? #ifdef STRICT typedef void *HANDLE; #define DECLARE_HANDLE(name) struct name##__ { int unused; }; typedef struct name##__ *name #else typedef PVOID HANDLE; #define DECLARE_HANDLE(name) typedef HANDLE name #endif typedef HANDLE *PHANDLE; DECLARE_HANDLE (HWND); I have been using HWND hWnd; for 4 years now and I really don''t konw what it is? what''s this -> name##__ *name; struct name##__ { int unused; }; What the hell. (int unused), is not used then why have (int unused) in there? Is HWND an int,pointer,const char* ? A pointer to a (struct) with one (var) thats not used? You have to have HWND why? if windows does not use (int unused) what does it use then? the pointer to nothing?

Share this post


Link to post
Share on other sites
Advertisement
It''s a 32 bit sized variable that you can''t do anything with except pass to windows functions. Treat it as an opaque type; don''t try to understand what goes on inside it. The OS knows what it is, and that''s good enough. I love Big Brother.

Share this post


Link to post
Share on other sites
The struct trick is only used so that you are forced to use the corect handle and prevents you from using another handle type instead.

Share this post


Link to post
Share on other sites
It''s a handle that manifests itself as either a pointer to a struct or a pointer to void. It doesn''t so much matter, as Windows handles it consistently internally. While the struct member is unused if present (as its name indicates), what IS used is the address to which the pointer points. What this means is that the HWND, as a pointer, doesn''t really point to anything; it...

Oh man, I just got dumped for prom. If I''m feeling like it, maybe I''ll add on to this later. Hope you can glean some useful info from the above.

Later,
ZE.

//email me.//zealouselixir software.//msdn.//n00biez.//
miscellaneous links

Share this post


Link to post
Share on other sites
it’s a fancy pointer!
there all just fancy pointer HICON,HCURSOR,HWND!
The data size is unknown ,because we only pass it to predefined functions.

I think I get it now , thanks.

Share this post


Link to post
Share on other sites
Windows doesn''t even necessarily use it as a pointer. Some handles are interpreted as integer values and used as an index into tables held by the operatng system. Either way it doesn''t matter. Just treat it as a 32 bit black box and don''t think about it any further.

Share this post


Link to post
Share on other sites
Same has above - it''s basicaly a numeric value used to identify some object. I''ve heard that windows used to just use the pointer to that object in memory (since it''a a simple way of getting a unique identifyer for that object), but people kept on using it to make changes to the object without going through the apis so Microsoft stopped (or is trying to stop) doing that.

Share this post


Link to post
Share on other sites
quote:
what''s this -> name##__ *name;

struct name##__ { int unused; };
What the hell.


## is an interesting thing you can use, but only in macros. Basically, it combines the left hand side with the right hand side to form one string. For example,

#define ADD_ABC_TO_END(param) param ## ABC

you can use the macro like this
ADD_ABC_TO_END(hello)
and the compiler will turn this line into
helloABC

Not very useful most of the time, but DECLARE_HANDLE uses it to declare custom structs quickly, as shown here. When it says DECLARE_HANDLE(HWND), the compiler turns this line into struct HWND__{ int unused; };

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!