JKop said:
alex posted:
typedef const char* LPCTSTR;
Wrong, LPCTSTR will expand to const wchar_t* if UNICODE is defined. Actually
the definition is:
typedef const TCHAR* LPCTSTR;
And TCHAR is:
#ifdef UNICODE
typedef wchar_t TCHAR
#else
typedef char TCHAR
#endif
typedef char* LPTSTR;
typedef unsigned long ULONG;
char value_name[] = "BlahBlah";
char value[] = "BlahBlah";
unsigned long poo = 0;
QueryStringValue(value_name,value,&poo);
Wrong, the third parameter of QueryStringValue must be the size in TCHARs of
the buffer pointed to by the second parameter. It will receive the amount of
TCHARs written. So it shouldn't be 0 initially.
Or even:
QueryStringValue("Hello","Goodbye",&poo);
This function will alter the second and third arguments, as they're not
declared const.
Why does Microsoft give the intrinsic types new names?
Because the information that you've got and the header files you've got
are
intended to be programming language NON-specific. If they used "char*",
then
some-one writing in a language called Blerg wouldn't know what's going on.
So they've thought up of new names to be used with every computer
programming language.
Not really. The header files are meant for C(++), they use C syntax so it'd
be a little hard to use them from a language that doesn't support C syntax.
Also, this particular function is not part of the Win32 API, but of ATL,
which is meant for C++ exclusively.
The main reason Microsoft renames intrinsic types is to standardise their
usage across the API, and to make them platform independant. With platform I
don't mean Windows vs. Unix, but Win16 vs. Win32 vs. Win64 and in the past
also Windows NT on the Alpha processors. For instance the LPARAM type, which
is used for Windows messaging, should be large enough to hold a pointer. So
on Win32 it'll expand to unsigned int, but on Win64 it's unsigned __int64.
Also, types such as WORD, DWORD are of a fixed length, regardless of what
word length your system has (which is a bit confusing, since it means DWORD
on Win32 is only a single machine word long (32 bits)). Then there are the
main pointer arithmic types such as INT_PTR which are guaranteed to have the
same length as a pointer.
In this situation we see another use of the typedefs. All string related
types with a T in them (TCHAR, LPTSTR, LPCTSTR) expand to either ansi or
wide characters depending on whether UNICODE is defined. In conjunction with
the _T macro you can use those types to write a program that can compile for
ansi and unicode without modification.