At 10/28/09 10:28 PM, Glaiel-Gamer wrote:
still doesnt make sense to me that you're casting a pointer type (char*) to an integer type (long)
A pointer is actually an integer, doesn't matter what type it points to. It could be double * and it would still be an integer ;)
SendMessage's two parameters, wParam and lParam are used for several things. They have chosen to use long, so that you can basically send any datatype that is less than 64bit. In this case, you cast a pointer to long, because the parameters are of long datatype, but in the other end (the receiving window) it will be cast back from long to wchar_t * or whatever datatype it uses.
C++ doesn't matter what is actually stored in the parameter, there is no bounds checking and no safe types. Therefore, you could for instance cast a double to long, and as long as the receiving application is aware that there should be a floating point there all will be well
Since C++ does not support run-time generics (C++ templates are compile-time) there is no proper way of sending different datatypes in the same function without using function overloading, which would require both ends to implement the same function on different datatypes, which basically is a waste of time for both the programmers and the application
And that's why you have to typecast! :P