The function is completely meaningless.
There is no point in sizeof(usrBuf)/sizeof(*usrBuf) to the pointer. This technique only works with arrays, not pointers.
Why is LPTSTR* usrBuf ? Pointer to pointer? What does the pointer to the pointer?
The transmitted pointer to the LPTSTR* usrBuf pointer LPTSTR* usrBuf force-converted to the LPTSTR type? It's pointless.
LPTSTR User[UNLEN+1] is an array of pointers. What do you mean? Why did you need an array of pointers? And what's the point of passing this array of pointers to a MessageBox , forcing it to LPTSTR ?
If you write your code in terms of T types, “changeers” (LP T STR), then stick to this rule everywhere. Those. not L"" , but _T("") .
In general, the code is meaningless. In some original form, he obviously spawned a sheet of error messages from the compiler. These messages were "stifled" by the arrangement of explicit type conversions. The code from this has become even more meaningless.
bool getCU(LPTSTR usrBuf, DWORD usrLen) { return GetUserName(usrBuf, &usrLen); } ... TCHAR User[UNLEN+1]; if (getCU(User, sizeof User / sizeof *User)) MessageBox(0, User, _T(""), 0);
But what is the whole idea? Why write a certain getCU wrapper getCU that actually does nothing but call GetUserName ?
typedef std::basic_string<TCHAR> tstring; tstring getCU() { TCHAR usrBuf[UNLEN+1]; DWORD usrLen = sizeof usrBuf / sizeof *usrBuf; if (!GetUserName(usrBuf, &usrLen)) usrBuf[0] = 0; return tstring(usrBuf); } ... tstring User = getCU(); if (!User.empty()) MessageBox(0, User.c_str(), _T(""), 0);