I want P / Invoke on GetWindowLongPtr and SetWindowLongPtr , and I see conflicting information about them.
Some sources say that on 32-bit platforms, GetWindowLongPtr is just a preprocessor macro that calls GetWindowLong, and GetWindowLongPtr does not exist as an entry point to user32.dll. For example:
- The pinvoke.net entry for SetWindowLongPtr has a static method that checks IntPtr.Size and then calls SetWindowLong or SetWindowLongPtr, commenting that "legacy OSs do not support SetWindowLongPtr." There is no explanation of what is meant by "obsolete OS".
- The answer at https://stackoverflow.com/a/312588/12 reads: "On 32-bit systems, GetWindowLongPtr is just a C macro that points to GetWindowLong."
Thus, these sources seem to indicate that * Ptr entry points are simply missing from the user32.dll version that ships with, say, 32-bit Windows 7.
But I do not see any signs of this in the MSDN documentation. According to MSDN, SetWindowLongPtr replaces SetWindowLong, simple and simple. And according to the requirements section of the SetWindowLongPtr page , it looks like SetWindowLongPtr is in user32.dll with Windows 2000 (both client and server versions). Again, entry points are not mentioned on 32-bit operating systems.
I suspect the truth is somewhere in between: when you tell the C ++ compiler to focus on older OSs (i.e. to compile something that will work on Win9x and NT4), then the header files declare SetWindowLongPtr as a macro, which calls SetWindowLong, but the entry point probably exists in Windows 2000 and later, and you will get it directly (instead of a macro) if you tell the compiler to target these platforms. But this is just a hunch; I really don't have the resources or the know-how to peek and test it.
It is also possible that the target platform plays a role - if you compile your application for the x86 platform, you should not call SetWindowLongPtr on a 64-bit OS. Again, I know enough to think about it, but I do not know how to find the answer. MSDN seems to suggest that SetWindowLongPtr is always valid.
Can someone tell me if it is safe to just P / Invoke to SetWindowLongPtr and do with it? (Assume that Windows 2000 and later.) Will P / Invoking to SetWindowLongPtr give me the correct entry point:
- if I run an application targeting the x86 platform on a 32-bit OS?
- if I run an application targeting the x86 platform on a 64-bit OS?
- Should I run an x64-based application on a 64-bit OS?
Joe White Jul 27 '10 at 12:45 2010-07-27 12:45
source share