Help, readers.
#include <windows.h>
void main() {
LONG_PTR x = 0;
SetWindowLongPtr(0, 0, x);
}
Ok, forget the fact that the above code doesn't do anything useful. But you'd expect it to compile without a warning, right? Well, compile it with the default Visual C++ options /Wp64 at a warning level of 4 and you're treated to the following:
cl -c -Wp64 -W4 test.cpp
warning C4244: 'argument' : conversion from 'LONG_PTR' to 'LONG', possible loss of data
I couldn't figure out why SetWindowLongPtr wouldn't actually take a LONG_PTR. Based on this warning it appears to take a LONG.
So I had a peek at the WINUSER.H header file at the actual function declaration. Turns out that there's two definitions, depending on whether a preprocessor switch (_WIN64) is defined. I'll summarize:
#ifdef _WIN64
LONG_PTR SetWindowLongPtr(
HWND hWnd,
int nIndex,
LONG_PTR dwNewLong
);
#else
#define SetWindowLongPtr SetWindowLong
#endif
I searched all the header files in Visual Studio to see if any of them actually define _WIN64, but none do, so I'm assuming this is something defined at compile time by a 64 bit compiler.
Is it just me, or are the header files somewhat broken in VS.NET 2003? The /Wp64 switch is supposed to spit out warnings if you're doing stuff that would cause you trouble with a 64 bit compiler. But calling SetWindowLongPtr is the right thing to do for 64-bit compatibility.
Anybody else run into this? Did you just give up and turn off the /Wp64 switch, or did you find a cleaner workaround? Or am I just doing something really stupid?
Posted
Jan 13 2005, 03:21 PM
by
keith-brown