Blog do projektu Open Source JavaHotel

sobota, 26 marca 2011

Windows and 64 bit

Next problem while migrating 32-bit application to 64 bit world.

Before migration (32 bit code)
SetWindowLongPtr( hwnd, GWLP_USERDATA, (long )this );
It is very common usage of GWLP_USERDATA property - keeping a pointer to struct of class containing more detailed information related to the window hwnd.

Later it can referenced:

static LRESULT CALLBACK WndProc (HWND hwnd, UINT _komunikaty, UINT wParam,LONG lParam) {
my_class *pointer;
pointer = (my_class *)GetWindowLongPtr(hwnd,GWLP_USERDATA);
// some logic related to window and my_class
....
}
Of course - it does not work after compiling as 64 bit application because 'long' data type is still 32 bit (different than in Linux where 'long' is 64 bit) but pointer is 64 bit.

In order to have this code working in 32 and 64 bit world it was necessary to modify this line:

  SetWindowLongPtr( hwnd, GWLP_USERDATA, ( LONG_PTR )this );

Also it was necessary to modify a simple function detecting if application is 32 or 64 bit - in MSVC I was unable to find any simple method (for instance : no compiler predefined constant).

#ifdef LINUX
inline bool is64Version() {
if (sizeof(long) == 8) { return true; }
else { return false; }
}
#else
inline bool is64Version() {
if (sizeof(void *) == 8) { return true; }
else { return false; }
}
#endif

Brak komentarzy:

Publikowanie komentarza