Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
544 views
in Technique[技术] by (71.8m points)

winapi - SetWindowLong vs SetWindowLongPtr

I am new to Windows programming, and have just come across setWindowLong and setWindowLongPtr(), and I was wondering what the difference was. I have heard people say that setWindowLongPtr() is better, however, whenever I call it, it is just a macro defined as setWindowLong().

Is there something wrong with my project?

question from:https://stackoverflow.com/questions/65854331/setwindowlong-vs-setwindowlongptr

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

SetWindowLong() operates on 32-bit LONG integers, so it is suitable only for 32bit builds, not for 64bit builds, when using options that deal with pointers (GWL_HINSTANCE, GWL_USERDATA, GWL_WNDPROC, DWL_DLGPROC, DWL_USER).

This is stated in the SetWindowLong() documentation:

Note This function has been superseded by the SetWindowLongPtr function. To write code that is compatible with both 32-bit and 64-bit versions of Windows, use the SetWindowLongPtr function.

SetWindowLongPtr() works with pointer-sized LONG_PTR integers, so it is suitable for both 32bit and 64bit builds.

This is stated in the SetWindowLongPtr() documentation:

Note To write code that is compatible with both 32-bit and 64-bit versions of Windows, use SetWindowLongPtr. When compiling for 32-bit Windows, SetWindowLongPtr is defined as a call to the SetWindowLong function.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...