type casting
-
Hi, Look at the code below
#define MAKEINTRESOURCE(i) (LPTSTR) ((DWORD) ((WORD) (i)))
If it's a type casting, I feel it's terrible. My question is: Inside memory, what the variable i look like after this terrible type casting Any information concerned is appreciated. Thank you Best regard. I confess that I am a stubborn guy, but why not put things thoroughly, logically and systematically clean. One concrete prolem is worth a thousand unapplied abstractions.
-
Hi, Look at the code below
#define MAKEINTRESOURCE(i) (LPTSTR) ((DWORD) ((WORD) (i)))
If it's a type casting, I feel it's terrible. My question is: Inside memory, what the variable i look like after this terrible type casting Any information concerned is appreciated. Thank you Best regard. I confess that I am a stubborn guy, but why not put things thoroughly, logically and systematically clean. One concrete prolem is worth a thousand unapplied abstractions.
-
Hi, Look at the code below
#define MAKEINTRESOURCE(i) (LPTSTR) ((DWORD) ((WORD) (i)))
If it's a type casting, I feel it's terrible. My question is: Inside memory, what the variable i look like after this terrible type casting Any information concerned is appreciated. Thank you Best regard. I confess that I am a stubborn guy, but why not put things thoroughly, logically and systematically clean. One concrete prolem is worth a thousand unapplied abstractions.
If you dont try to modify the pointer returned from MAKEINTRESOURCE, things are okay. Anyhow MSDN has this warning :- "The return value from MAKEINTRESOURCE should be passed only to the Win32 resource-management functions" Nish
Regards, Nish Native CPian. Born and brought up on CP. With the CP blood in him.
-
The high word of 'i' will be cleared, since the WORD type cast will remove it. The DWORD type adds a high word of zero's. The LPTSTR does just change the type of the DWORD to a character pointer, with no effects on the bits in memory.
Where's Christian?? He won't like that c-style cast one little bit :) Signature space for rent. Apply Within.
-
Hi, Look at the code below
#define MAKEINTRESOURCE(i) (LPTSTR) ((DWORD) ((WORD) (i)))
If it's a type casting, I feel it's terrible. My question is: Inside memory, what the variable i look like after this terrible type casting Any information concerned is appreciated. Thank you Best regard. I confess that I am a stubborn guy, but why not put things thoroughly, logically and systematically clean. One concrete prolem is worth a thousand unapplied abstractions.
Yes, this is type casting. Because the compiler verifies that all computations in your program use compatible datatypes, type casting becomes necessary when you have two data types in a calculation that are not compatible by default. The MAKEINTRESOURCE macro is a very useful macro, that does serve a good purpose, and is not considered terrible. It allows you to refer to a resource in your module by either a NULL terminated string, or a resource ID. This type of cast, where you place the target data type in ( ), is called a C-style cast. This is equivalent to the reinterpret_cast operator in C++. It tells the compiler to disregard the format of the data that you are type casting from, and think of it as another, possibly incompatible format. So this type-cast operation does not change anything inside of memory, it just makes the compiler think of your type-cast variable as another format so that it will not complain that you are trying to form a calculation with two incompatible types.
Build a man a fire, and he will be warm for a day
Light a man on fire, and he will be warm for the rest of his life! -
Hi, Look at the code below
#define MAKEINTRESOURCE(i) (LPTSTR) ((DWORD) ((WORD) (i)))
If it's a type casting, I feel it's terrible. My question is: Inside memory, what the variable i look like after this terrible type casting Any information concerned is appreciated. Thank you Best regard. I confess that I am a stubborn guy, but why not put things thoroughly, logically and systematically clean. One concrete prolem is worth a thousand unapplied abstractions.
answer: Pointer to a null-terminated string of 16-bit Unicode characters. Aizik Yair Software Engineer