-
June 15th, 2011, 07:15 PM
#1
Typecast from a const char* to an integer
I'm looking for something like
Code:
SendMessage(hStatic, WM_SETTEXT, 0, cast<LPARAM>("mytext"));
LPARAM is actually an integer btw, right?
-
June 15th, 2011, 07:53 PM
#2
Re: Typecast from a const char* to an integer
Why not
reinterpret_cast< LPARAM >( "abc" )
or
(LPARAM)"abc"
Originally Posted by paprica
LPARAM is actually an integer btw, right?
typedef LONG_PTR LPARAM;
typedef long LONG_PTR, *PLONG_PTR;
of course long can be any byte size >= char
0100 0111 0110 1111 0110 0100 0010 0000 0110 1001 0111 0011 0010 0000 0110 0110 0110 1111 0111 0010
0110 0101 0111 0110 0110 0101 0111 0010 0010 0001 0010 0001 0000 0000 0000 0000 0000 0000 0000 0000
-
June 16th, 2011, 03:56 AM
#3
Re: Typecast from a const char* to an integer
I've been taught that c-style casts are bad.
Are you sure that reinterpret_cast is the right choice? It just converts pointer to pointer or pointer to integer and vice versa...
-
June 16th, 2011, 04:16 AM
#4
Re: Typecast from a const char* to an integer
Originally Posted by paprica
Are you sure that reinterpret_cast is the right choice?
This is exactly the sort of thing that reinterpret cast is for. I use this technique all the time to pass object addresses to a window, in a message. I use reinterpret cast to convert the pointer back again to its real type at the receiving end.
"It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong."
Richard P. Feynman
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|