I was wondering, what is the correct usage of GetComputerName. Should it be
TCHAR computerName[1024 + 1];
DWORD size = 1024;
GetComputerName(computerName, &size);
or
TCHAR computerName[1024];
DWORD size = 1024;
GetComputerName(computerName, &size);
The size passed in the
lpnSizeparameter reflects the amount of space available in the buffer, including space for the null terminator. Either of your statements will work, because in the first one you’re just allocating one more byte than what you’re saying is available.You may want to use
MAX_COMPUTERNAME_LENGTHinstead, which is much less than 1024.