So what you are saying is that size will recieve the four bytes that will be the username?
|
No, as the documentation states, upon calling this function, you tell Windows the size in TCHARs of the buffer you are going to provide to the OS to return the string. In the first parameter you provide the address of this buffer. The OS then determines the length of the string it is going to copy to name. If the buffer is equal to or larger than the full string, it will copy to your buffer the whole string. If the buffer you have provided isn't big enough (as specified by the info you passed in in size), then it won't over-run the buffer, and will truncate the string so as to prevent memory corruption beyond the provided buffer. In any case, it will return in the size parameter, the length actually copied. It is really very, very, very, simple. And the documentation is very, very, clear ...
lpnSize [in, out]
On input, this variable specifies the size of the lpBuffer buffer, in TCHARs. On output, the variable receives the number of TCHARs copied to the buffer, including the terminating null character.
|
This is one of the most common 'design patterns' used by the Windows Api. For example, check out GetCurrentDirectory(). First parameter is a pointer to the string buffer. Second parameter an [in, out] where you tell windows how much room you've made, and Windows tells you back how much it used of what you supposedly gave it. And if you lie, bad things will happen. You'll be punished. Or at least you used to be punished. In Windows 95 you got the blue screen of death. In Windows 2000, an ignorant message telling you you've corrupted memory at such an such an address, and your program will be shut down. In Windows XP a SLIGHT APOLOGY. And in Windows 7 a sincere apology, with an attempt made to make up for it happening. Microsoft mellowing out with age.
I don't believe any of the standard non-pointer C/C++/Api data types exapand with 64 bit EssGeEich. All the pointer data types do though, even opaque pointers such as Window Handles of one type and another. All last week I played with 64 bit Windows. Was fun. I've little to no need of it though.