How do I call SetWindowLong() in the 64-bit versions of Windows?

后端 未结 3 1378
夕颜
夕颜 2021-02-18 16:55

In the header file WinUser.h, there is a part in which the constants of the second parameter of SetWindowLong() are defined.

// ...

#define GWL_WNDP         


        
相关标签:
3条回答
  • 2021-02-18 17:18

    Also make sure you're NOT defining the following:

    #define NOWINOFFSETS

    which makes GWL_*, GCL_*, ie. GetWindowLongPtr and family, as well as associated routines available.

    0 讨论(0)
  • 2021-02-18 17:19
        As specified in <WinUser.h>
        //If config is _WIN64 then use new versioned macro
    
        #define GWLP_WNDPROC        (-4)
        #define GWLP_HINSTANCE      (-6)
        #define GWLP_HWNDPARENT     (-8)
        #define GWLP_USERDATA       (-21)
        #define GWLP_ID             (-12)
    
        //else for _WIN32
    
        #undef GWL_WNDPROC
        #undef GWL_HINSTANCE
        #undef GWL_HWNDPARENT
        #undef GWL_USERDATA
    
    0 讨论(0)
  • 2021-02-18 17:29

    Some of the window data values (the ones that refer to "pointer sized" objects like the window procedure, for example) need to be 64 bit in an x64 build. The old SetWindowLong() and GetWindowLong() functions are limited to DWORD sized (32 bit) values for backwards compatibility, and Microsoft have introduced new versions, SetWindowLongPtr() and GetWindowLongPtr() that allow you to work with pointer-sized values (32 bit in a 32 bit build, and 64 bit in a 64 bit build).

    These days it is recommended that you always use SetWindowLongPtr() and the GWLP_xxx constants, whether you are building for 32 or 64 bit, but in a 64 bit build you need to use the new functions and so the defines are #undefined to cause build errors that force you to fix your code.

    0 讨论(0)
提交回复
热议问题