Jump to content
  • Advertisement
Sign in to follow this  
rayli1107

SetWindowLongPtr() function?

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

Can anyone tell me which header it's in? According to MSDN it's in windows.h but I included windows.h and it still can't recognize SetWindowLongPtr() function. Thanks.

Share this post


Link to post
Share on other sites
Advertisement
Looking through the winuser.h file I found these lines
#ifdef _WIN64

WINUSERAPI
LONG_PTR
WINAPI
GetWindowLongPtrA(
HWND hWnd,
int nIndex);
WINUSERAPI
LONG_PTR
WINAPI
GetWindowLongPtrW(
HWND hWnd,
int nIndex);
#ifdef UNICODE
#define GetWindowLongPtr GetWindowLongPtrW
#else
#define GetWindowLongPtr GetWindowLongPtrA
#endif // !UNICODE

WINUSERAPI
LONG_PTR
WINAPI
SetWindowLongPtrA(
HWND hWnd,
int nIndex,
LONG_PTR dwNewLong);
WINUSERAPI
LONG_PTR
WINAPI
SetWindowLongPtrW(
HWND hWnd,
int nIndex,
LONG_PTR dwNewLong);
#ifdef UNICODE
#define SetWindowLongPtr SetWindowLongPtrW
#else
#define SetWindowLongPtr SetWindowLongPtrA
#endif // !UNICODE

#else /* _WIN64 */

#define GetWindowLongPtrA GetWindowLongA
#define GetWindowLongPtrW GetWindowLongW
#ifdef UNICODE
#define GetWindowLongPtr GetWindowLongPtrW
#else
#define GetWindowLongPtr GetWindowLongPtrA
#endif // !UNICODE

#define SetWindowLongPtrA SetWindowLongA
#define SetWindowLongPtrW SetWindowLongW
#ifdef UNICODE
#define SetWindowLongPtr SetWindowLongPtrW
#else
#define SetWindowLongPtr SetWindowLongPtrA
#endif // !UNICODE

#endif /* _WIN64 */


The lines of importance here are
#ifdef _WIN64

... // 64 bit stuff

#else /* _WIN64 */

#define GetWindowLongPtrA GetWindowLongA
#define GetWindowLongPtrW GetWindowLongW

...

#define SetWindowLongPtrA SetWindowLongA
#define SetWindowLongPtrW SetWindowLongW

...

#endif /* _WIN64 */

So apparently the SetWindowLongPtr is only actually used in 64 bit applications. In 32 bit apps it falls back to the SetWindowLong function which takes a LONG and not a LONG_PTR as third parameter.

Why they would do this is beyond me. It will raise a compile error if you try to use SetWindowLongPtr as MSDN tells you.

Well, anyway you can use the SetWindowLongPtr function in 32 bit applications if you send it a LONG value and not a LONG_PTR value.

Regards

*Edit

That is you should still only have to include windows.h as MSDN says.

[Edited by - staaf on May 21, 2005 4:59:11 PM]

Share this post


Link to post
Share on other sites
I found that the "correct" way of calling SetWindowLongPtr in MSVC 2003 is this:


#pragma warning(push)
#pragma warning(disable: 4244) // Microsoft's macros screw up 64bit compat warnings
SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR)cs->lpCreateParams);
#pragma warning(pop)




The reason you must push/pop the warnings, is the way windows.h does the #defines, it complains about 64 bit compatability, even when there is no problem (the defines take care of it, but the compilers dosn't know that).

The important bit for you is the (LONG_PTR) cast. This will ensure the data types and functions and whatever are correct in both 64 and 32 bit modes.

All it requires is windows.h - you should be fine.

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.

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!