TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: NEIL HELLER
from: CHRIS DOWNS
date: 1997-08-23 21:33:00
subject: Re: PRINTING POINTER VALU

 NH> Today I saw an interesting expression like I had never seen before. 
 NH> In a call to SendMessage, the variable that's sent as the LPARAM is (I
 NH> guess) supposed to be a long.  The original programmer wanted to send
 NH> a FAR pointer to a CSTRING (while compiling the whole shebang in the
 NH> medium modle) so what he did was a double cast (or at least that's
 NH> what I took it to be):
 NH> (long)(LPSTR)foovar...
 NH> We are now compiling everything in the large modle so I was advised to
 NH> change the above to:
 NH> (LPARAM)foovar...
 NH> My question is this:  was I correct in assuming that the first example
 NH> above is a double cast?  If so, are double casts common elsewhere?
 I wouldn't take the advice to cast foovar directly to an 
 LPARAM.  What the double cast is doing is a class member defined 
 type conversion.  
 When foovar is converted to an LPCSTR (my compiler doesn't allow
 a conversion to the non-const string) it returns the address of the
 buffer the CString object encapsulates.  That address value then
 gets converted to a long.
 So unless there's a function that can convert a CString into an 
 LPARAM, either your compiler won't allow it or else you probably
 will be passing some useless value.
 NH> In any case wouldn't the LPSTR cast have done the trick or is the
 NH> second cast to long necessary to change the segment:offset notation
 NH> for the 16-bit environment to something a bit more flat?
 void foobar(int type, long additional_info_of_some_type);
 If you want to call foobar() with a CString, the cast to the LP(C)STR 
 does a type conversion and the cast to the long is to satisfy the 
 semantics of the function you want to call.
---
 þ Blue Wave/QWK v2.12 þ
---------------
* Origin: St. Louis Users Group (1:100/4)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.