Question Details

No question body available.

Tags

winapi

Answers (2)

January 14, 2026 Score: 1 Rep: 4,076 Quality: Low Completeness: 60%

Q1: Yes. See nIndex parameter definition of SetWindowLongPtrW (and later on for in remarks about extra window memory). Non-negative indexes are for accessing that extra window memory, if any; GWLPUSERDATA is a negative constant to access always-existing per-window field. Its only difference from other GWLP fields is its intended usage.

Q2: sizeof(void), pointer-sized. Technically it's LONGPTR so it's not a pointer but an integer; it is however intended to be round-trippable with pointers just like C++'s intptrt. Most of predefined GWLP* fields do store pointers.

Q3: Yes. See again definition of nIndex parameter in SetWindowLongPtrW: "Sets the user data associated with the window".

Its intended usage is to store per-window private state. E.g. in C++ it is common to have a C++ class describing an instance of a window (maybe of some particular window class); GWLPUSERDATA would then used to store this C++ class instance of a window so that window procedure can get C++ class instance from window handle.

January 15, 2026 Score: 0 Rep: 610,331 Quality: Low Completeness: 40%

Q1. cbWndExtra allocates extra bytes that are accessible via positive indexes in (Get|Set)WindowLong[Ptr]. OS-provided fields are accessible via negative indexes. This includes GWLP_USERDATA (-21).