The size passed in the lpnSize parameter reflects the amount of free space in the buffer, including space for the null terminator. Any of your statements will work, because in the first you just allocate one more byte than what you say is available.
Instead, you can use MAX_COMPUTERNAME_LENGTH , which is much less than 1024.
TCHAR computerName[MAX_COMPUTERNAME_LENGTH + 1]; DWORD size = sizeof(computerName) / sizeof(computerName[0]); GetComputerName(computerName, &size);
source share