Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

SetClassLongPtr and GetClassLongPtr bug??

205 views
Skip to first unread message

Ron Francis

unread,
Jul 8, 2007, 10:38:31 PM7/8/07
to
Windows XP Professional SP1
VS2005 SP1
Windows Server 2003 R2 Platform SDK

After porting some code from VC6 to VS2005, I've been trying to clean up
some code warnings and came across this ...

If I try to compile:
SetClassLongPtr ( ghWnd, GCLP_HCURSOR, hCursor );
I get an error: 'SetClassLongA' : cannot convert parameter 3 from 'HCURSOR'
to 'LONG'
Shouldn't this be 'HCURSOR' to 'LONG_PTR'?

So I try:
SetClassLongPtr ( ghWnd, GCLP_HCURSOR, (LONG) hCursor );
and get a warning:
'type cast' : pointer truncation from 'HCURSOR' to 'LONG'

SetClassLongPtr ( ghBorderWnd, GCLP_HCURSOR, (LONG_PTR) hCursor );
error : cannot convert parameter 3 from 'HCURSOR' to 'LONG' ??? Why is it
expecting a LONG parameter?

SetClassLongPtr ( ghWnd, GCLP_HCURSOR, (LONG)(LONG_PTR) hCursor );
The compiler is happy with this?!

I also run into the same sort of problems with SetWindowLong()

OldListProc = (WNDPROC) SetWindowLongPtr ( hList, GWLP_WNDPROC, (WNDPROC)
SubListProc );
'SetWindowLongA' : cannot convert parameter 3 from 'WNDPROC' to 'LONG'

OldListProc = (WNDPROC) SetWindowLongPtr ( hList, GWLP_WNDPROC, (LONG)
(WNDPROC) SubListProc );
pointer truncation from 'WNDPROC' to 'LONG'

OldListProc = (WNDPROC) SetWindowLongPtr ( hList, GWLP_WNDPROC, (LONG)
(LONG_PTR) (WNDPROC) SubListProc );
'type cast' : conversion from 'LONG' to 'WNDPROC' of greater size
Happy with the parameter now but why does it think that it's returning a
LONG??

OldListProc = (WNDPROC) (LONG_PTR) SetWindowLongPtr ( hList, GWLP_WNDPROC,
(LONG) (LONG_PTR) (WNDPROC) SubListProc );
This is now acceptable, but why should I have to tell the compiler that
SetWindowLongPtr() is supposed to return a LONG_PTR?

Not a huge problem for me, but is it a bug?
If it's not, then is help file wrong or not supply enough information?


Regards,
Ron Francis
www.RonaldFrancis.com


Igor Tandetnik

unread,
Jul 8, 2007, 11:18:49 PM7/8/07
to
"Ron Francis" <rfra...@senet.com.au> wrote in message
news:eLk9YKdw...@TK2MSFTNGP03.phx.gbl

> After porting some code from VC6 to VS2005, I've been trying to clean
> up some code warnings and came across this ...
>
> If I try to compile:
> SetClassLongPtr ( ghWnd, GCLP_HCURSOR, hCursor );
> I get an error: 'SetClassLongA' : cannot convert parameter 3 from
> 'HCURSOR' to 'LONG'
> Shouldn't this be 'HCURSOR' to 'LONG_PTR'?

http://groups.google.com/group/microsoft.public.win32.programmer.ui/browse_frm/thread/6c8f315a9491ae5d

--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925


Ron Francis

unread,
Jul 10, 2007, 10:33:02 PM7/10/07
to
"Igor Tandetnik" <itand...@mvps.org> wrote in message
news:eDciWjdw...@TK2MSFTNGP04.phx.gbl...

> "Ron Francis" <rfra...@senet.com.au> wrote in message
> news:eLk9YKdw...@TK2MSFTNGP03.phx.gbl
>> After porting some code from VC6 to VS2005, I've been trying to clean
>> up some code warnings and came across this ...
>>
>> If I try to compile:
>> SetClassLongPtr ( ghWnd, GCLP_HCURSOR, hCursor );
>> I get an error: 'SetClassLongA' : cannot convert parameter 3 from
>> 'HCURSOR' to 'LONG'
>> Shouldn't this be 'HCURSOR' to 'LONG_PTR'?
>
> http://groups.google.com/group/microsoft.public.win32.programmer.ui/browse_frm/thread/6c8f315a9491ae5d
>
> --
> With best wishes,
> Igor Tandetnik

Thanks Igor,

That's a very comprehensive answer.
I feel pretty stupid now, because I usually google before I ask questions
here, although I couldn't find your link.

Cheers.
Ron.


0 new messages