Can someone please help me resolve this warnings? Ive fixed many of the others, its just these ones that I'm stuck at.
I'm using Visual Studio 2005 Standard w/SP1. MFC Dialog App (non-unicode)
warning C4311: 'type cast' : pointer truncation from 'HICON' to 'int'
warning C4312: 'type cast' : conversion from 'unsigned long' to 'HICON' of greater
Code:
#define BTNST_AUTO_GRAY (HICON)(0xffffffff - 1L)
// Set icon when the mouse is IN the button
hIconIn = (HICON)::LoadImage(hInstResource, MAKEINTRESOURCE(nIconIn), IMAGE_ICON, nCxDesiredIn, nCyDesiredIn, 0);
switch ((int)hIconIn) // C4311
{
case NULL:
break;
case (int)BTNST_AUTO_GRAY: // C4312
hIconOut = BTNST_AUTO_GRAY;
break;
case (int)BTNST_AUTO_DARKER:
hIconOut = BTNST_AUTO_DARKER;
break;
default:
hIconOut = (HICON)::LoadImage(hInstResource, MAKEINTRESOURCE(nIconOut), IMAGE_ICON, nCxDesiredOut, nCyDesiredOut, 0);
break;
} // switch
C4311: 'type cast' : pointer truncation from 'LRESULT (__stdcall *)(HWND,UINT,WPARAM,LPARAM)' to 'DWORD'
C4312: 'type cast' : conversion from 'LONG' to 'WNDPROC' of greater size
These warnings are generated only when you have the 'detect 64-bit portability issues' flag (/Wp64) set. The issue is that HICON will be 64-bits in Win64 but int will still be 32-bits.
If you have no future plans to compile your code for Win64 then you may safely ignore these warnings - or turn of the /Wp64 flag so that they are not generated.
However, it is always good programming practice not to make assumptions about the sizes of particular types so maybe you should deal with these issues now. The same situation occurred years ago with the migration from 16-bit to 32-bit programmers everywhere had to deal with it then.
Bookmarks