Should I avoid typedef, try to use primitive names and cast when possible?
c++, casting, typedef, types, winapi
Solution
1) The Win32 API is actually C, not C++.
The distinction becomes more important if you consider stuff like MFC or ATL, both of which are "object-oriented", C++-only APIs. And both of which are mercifully becoming (have become?) obsolete.
2) Microsoft likes to use lots of macros and typedefs. I can't say whether that's "good" or "bad". It's simply a fact of life. And it'll become second nature to you if you work with Windows for any length of time.
3) Most importantly - Yes: you should definitely follow the Microsoft conventions when you use the Microsoft APIs. Using "HANDLE" when the MSDN page says "HANDLE" is a Good Thing. Similar advice holds for "LPxxx", "TRUE", "FALSE", "INVALID_HANDLE", "HRESULT" etc etc. If that's what it says in MSDN, then that's what you should use.
Not only will it make your code more readable ... but, surprisingly often, it can also prevent subtle bugs you might cause by "second guessing" the "true type".
Do not try to "second guess" the types. It's just a Bad Idea.
Following the standard conventions will make life easier, safer, more reliable and more portable.
IMHO...
Problem
I'm not sure of the vocabulary here, but hopefully I can make myself understood. As I'm working through the winapi with a less-than-rock-solid knowledge of C++, I find a lot of typedef stuff that, for me, seems to overcomplicate the issue and add one more thing I have to remember. For example, `UINT` instead of `unsigned int`, `HBITMAP` which turns out is just a `HANDLE`, and lots of others. My question is, can / should I substitute the more generic version of the type when possible, and just cast it down when it's needed (and, what's this called)? For example, I'd like to write `void SomeFunction(unsigned int some_int) { ... }` instead of `void SomeFunction(UINT some_int) { ... }` `HANDLE hBMP = LoadImage(...); ImageList_Add(... (HBITMAP) hBMP ...);` instead of `HBITMAP hBMP = ...` Is this good for newcomers, bad practice in general, or what?