The lpnSize parameter for GetComputerNameEx specifies the total
size of the buffer (in characters).
However, the current code calculated the amount of bytes.
Since only GetComputerNameExA was used and because sizeof(CHAR) == 1
the result was correct but the math was wrong.
Credit goes to @byteboon
int status;
char* ws = Workstation;
CHAR computerName[MAX_COMPUTERNAME_LENGTH + 1];
- DWORD nSize = sizeof(computerName) * sizeof(CHAR);
+ DWORD nSize = sizeof(computerName) / sizeof(CHAR);
if (!Workstation)
{
{
int status;
CHAR computerName[MAX_COMPUTERNAME_LENGTH + 1];
- DWORD nSize = sizeof(computerName) * sizeof(CHAR);
+ DWORD nSize = sizeof(computerName) / sizeof(CHAR);
char* name = TargetName;
if (!name)
{
-
if (!GetComputerNameExA(ComputerNameDnsHostname, computerName, &nSize))
return -1;
char* name;
int status;
CHAR computerName[MAX_COMPUTERNAME_LENGTH + 1];
- DWORD nSize = sizeof(computerName) * sizeof(CHAR);
+ DWORD nSize = sizeof(computerName) / sizeof(CHAR);
if (!GetComputerNameExA(type, computerName, &nSize))
return -1;