Jump to content
  • Advertisement
Sign in to follow this  
ak09

[Win32] Addresses

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

As an example, the SendMessage(hWnd, CB_GETCURSEL, 0, 0) function returns the selected index of a combo box.
If my purpose is to read this index multiple times, I should call this function multiple times. Or don't I?

Instead, is there an address where these kind of stuff are stored so I can and use it for making things easier?

Share this post


Link to post
Share on other sites
Advertisement

No, Windows does not offer you access to the address of the internal variables it uses to implement the functionality of the various controls. That's a good thing, as some of these may correspond directly to internal variables, while others are probably inferred and are calculated based on other variables. Even strings are returned by copying rather than by addresses. You can always just retrieve the value at the beginning of a function and cache it for the rest of the function.

Share this post


Link to post
Share on other sites

No, Windows does not offer you access to the address of the internal variables it uses to implement the functionality of the various controls. That's a good thing, as some of these may correspond directly to internal variables, while others are probably inferred and are calculated based on other variables. Even strings are returned by copying rather than by addresses. You can always just retrieve the value at the beginning of a function and cache it for the rest of the function.

This, and how it works internally may change between versions of Windows. It is horrific to see programmers get a handle from a Windows function, subtract a magic number from it, and dereference it to get data that they're looking for out of thin air. This will essentially do that, after all is compiled and shipped, and people trying to figure out why it doesn't work on Windows 9 will come looking for you.

Share this post


Link to post
Share on other sites

No, Windows does not offer you access to the address of the internal variables it uses to implement the functionality of the various controls. That's a good thing, as some of these may correspond directly to internal variables, while others are probably inferred and are calculated based on other variables. Even strings are returned by copying rather than by addresses. You can always just retrieve the value at the beginning of a function and cache it for the rest of the function.

This, and how it works internally may change between versions of Windows. It is horrific to see programmers get a handle from a Windows function, subtract a magic number from it, and dereference it to get data that they're looking for out of thin air. This will essentially do that, after all is compiled and shipped, and people trying to figure out why it doesn't work on Windows 9 will come looking for you.

 

That is insane! Has anyone ever written code like that? I know that handles are supposed to behave as opaque identifiers under Windows but do people actually go hunting information by dereferencing it? This.. like.. misses the entire point of handles and component encapsulation. (although I have to agree I have seen better interfacing mechanisms than messages)

Share this post


Link to post
Share on other sites

If using ATL, atlctrls.h has a nice helper method for getting the selection.

If not, then you can easily write your own little helper method that at least saves you from having to pass in all of those arguments.

Share this post


Link to post
Share on other sites



No, Windows does not offer you access to the address of the internal variables it uses to implement the functionality of the various controls. That's a good thing, as some of these may correspond directly to internal variables, while others are probably inferred and are calculated based on other variables. Even strings are returned by copying rather than by addresses. You can always just retrieve the value at the beginning of a function and cache it for the rest of the function.

This, and how it works internally may change between versions of Windows. It is horrific to see programmers get a handle from a Windows function, subtract a magic number from it, and dereference it to get data that they're looking for out of thin air. This will essentially do that, after all is compiled and shipped, and people trying to figure out why it doesn't work on Windows 9 will come looking for you.

That is insane! Has anyone ever written code like that? I know that handles are supposed to behave as opaque identifiers under Windows but do people actually go hunting information by dereferencing it? This.. like.. misses the entire point of handles and component encapsulation. (although I have to agree I have seen better interfacing mechanisms than messages)
Yeah, I've seen crazy code like that. People would rather offset from an unknown pointer than use calls to established interfaces, and a lot of people offset from a pointer to an object to get to private member variables and virtual functions. Additionally, see Raymond Chen's take on it:
http://blogs.msdn.com/b/oldnewthing/archive/2003/12/23/45481.aspx Edited by Ectara

Share this post


Link to post
Share on other sites

Windows also uses handles to abstract objects so they can be relocated internally whenever it feels the need, doesn't it?

Share this post


Link to post
Share on other sites

Khatharr, on 28 May 2013 - 21:53, said:
Windows also uses handles to abstract objects so they can be relocated internally whenever it feels the need, doesn't it?

Properly, yes. For the most part, it is a complete abstraction, perhaps an index into a pointer table, that allows for reallocation or reimplementation. Some nefarious APIs don't follow this, but most do.

Share this post


Link to post
Share on other sites

http://blogs.msdn.com/b/oldnewthing/archive/2003/12/23/45481.aspx

 

Wow. I don't know what is worse, the developers doing crazy stuff like that, or microsoft encouraging them by patching the OS for it to still work...

It's less encouragement to continue, and more wanting to sell copies of Windows because people will blame Windows and refuse to update if their old software no longer works. No matter how important it is to teach a lesson, in the end, if it means losing sales to do it, it probably isn't worth it.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!