GetWindowLongPtr

II’m writing a tabbed version of explorer as a little side project. It’s being written in C++ as a little excercise in using the Shell APIs, and I’m writing it in straight Win32 API calls, without a framework (this is in part due to the influence of Colin Jeanne, and partly because this is how I write code at work). Anyway, as a consequence, I needed to pass an instance pointer back to my WindowProc function so that I could invoke the proper member functions to handle messages. Raymond Chen demonstrates this in his scratch program through the use of the WM_NCCREATE message and Set/GetWindowLongPtr functions.

MSVC doesn’t like that very much in the current platform SDK. SetWindowLong is a function that is used to store a bit of extra data to be associated with a window. Since a LONG is 32 bits on x86 and 64 bits on x64, a new function was created so we could use a single function for storing a pointer associated with a window (since this is a very common use scenario), and so SetWindowLongPtr exists. It stores 32 bits on an x86 platform and 64 bits on x64. Unfortunately, the 64-bit compatibility warnings seem to be broken with the current platform sdk. It tells me:

warning C4312: ‘reinterpret_cast’ : conversion from ‘LONG’ to ‘CExplorerWindow *’ of greater size c:\svn\tabbedexplorer\explorerwindow.cpp 182

Instead of disabling 64-bit warnings altogether, my only option is to disable warnings 4312 and 4244 for this source file:

#pragma warning(disable : 4312)
#pragma warning(disable : 4244)

I’m not happy with this solution however, so hopefully I will find a better solution soon.

This post was written in “Windows Live Writer“. More on that tommorow.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>