For Programmers: Free Programming Magazines  


Home > Archive > VC Language > January 2006 > type cast warnings









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author type cast warnings
ama

2006-01-28, 7:07 pm

Hi,

how should i typecast a HICON to LONG without a warning ?

[VS2005]
.....

HICON icon = LoadIcon(_Module.GetResourceInstance(),
MAKEINTRESOURCE(IDI_ICON1));
if( icon )
::SetClassLong(m_hWnd, GCL_HICON, (LONG)icon);
.....
warning C4311: 'type cast' : pointer truncation from 'HICON' to 'LONG'

Thanks.


Victor Bazarov

2006-01-28, 7:07 pm

ama wrote:
> how should i typecast a HICON to LONG without a warning ?
>
> [VS2005]
> ....
>
> HICON icon = LoadIcon(_Module.GetResourceInstance(),
> MAKEINTRESOURCE(IDI_ICON1));
> if( icon )
> ::SetClassLong(m_hWnd, GCL_HICON, (LONG)icon);
> ....
> warning C4311: 'type cast' : pointer truncation from 'HICON' to 'LONG'


You can't avoid this. Apparently, 'HICON' and 'LONG' types in your
system have different sizes. It is quite possible that 'HICON' is
64 bits. 'LONG' is 32 bits (don't ask why). Any attempt to convert
a 64 bit value into a 32 bit value causes truncation.

V


James Park

2006-01-28, 7:07 pm

"ama" <a.m.a@videotron.ca> wrote in message
news:yrSCf.40789$lM1.502824@weber.videotron.net...
> Hi,
>
> how should i typecast a HICON to LONG without a warning ?
>
> [VS2005]
> ....
>
> HICON icon = LoadIcon(_Module.GetResourceInstance(),
> MAKEINTRESOURCE(IDI_ICON1));
> if( icon )
> ::SetClassLong(m_hWnd, GCL_HICON, (LONG)icon);
> ....
> warning C4311: 'type cast' : pointer truncation from 'HICON' to 'LONG'
>
> Thanks.


http://msdn.microsoft.com/library/e...ng_pointers.asp


ama

2006-01-28, 9:58 pm


> You can't avoid this. Apparently, 'HICON' and 'LONG' types in your
> system have different sizes. It is quite possible that 'HICON' is
> 64 bits. 'LONG' is 32 bits (don't ask why). Any attempt to convert
> a 64 bit value into a 32 bit value causes truncation.
>
> V


thanks, ill keep this in mind


Abdo Haji-Ali

2006-01-29, 3:57 am

Use SetClassLongPtr() instead which is "compatible with both 32-bit and
64-bit Microsoft® Windows®"

--
Abdo Haji-Ali
Programmer
In|Framez

"ama" <a.m.a@videotron.ca> wrote in message
news:yrSCf.40789$lM1.502824@weber.videotron.net...
> Hi,
>
> how should i typecast a HICON to LONG without a warning ?
>
> [VS2005]
> ....
>
> HICON icon = LoadIcon(_Module.GetResourceInstance(),
> MAKEINTRESOURCE(IDI_ICON1));
> if( icon )
> ::SetClassLong(m_hWnd, GCL_HICON, (LONG)icon);
> ....
> warning C4311: 'type cast' : pointer truncation from 'HICON' to 'LONG'
>
> Thanks.
>
>



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com