Handle Win64 Errors Related to Obsolete Win32 Constants

Submit New Article

November 24, 2008 11:00 PM PST



Challenge

Address Win64* compilation errors related to old Win32* constants. A few of the constants used with the Win32 APIs have been modified for Win64; as a result, using the old constants will generate an error, which might look something like this:

error C2065: 'GWL_HINSTANCE' : undeclared identifier

During the course of porting applications to the Win64 environment, it is necessary to identify and resolve compiler warnings and errors. The procedure for identifying these errors is addressed in the separate item "How to Use Makefiles to Resolve Win64 Porting Issues."


Solution

Replace the old constant with the new constant. Win64 uses the LLP64 (or P64) uniform data model, in which pointers and long long are 64 bits, but int and long are 32 bits. To support this data model and to provide compatibility with the existing Win32 code, new data types have been defined in Win64.

As an example using the Win32 API, the following code:

LONG iVal = GetWindowLong(hWnd, GWL_HINSTANCE);

should be changed to the following:

LONG_PTR iVal = GetWindowLongPtr(hWnd, GWLP_HINSTANCE);

Note that, in addition, four of the existing Win32 APIs that are used to set or get polymorphic window class data items have been changed, including the following:

  • Get/SetClassLong changed to Get/SetClassLongPtr
  • Get/SetWindowLong changed to Get/SetWindowLongPtr

 

Further details on this topic are available from http://msdn.microsoft.com/en-us/library/ms633588(VS.85).aspx*


Source

Porting Microsoft Windows Applications to Intel® Itanium® Processor Systems