如题,目前已经确认了动态内存分配没有问题,SetText没有问题(上面还有一个格式一摸一样的MyGetUserName)
GetComputerName时,会返回FALSE
[C] 纯文本查看 复制代码 char *MyGetComputerName() {
char *computerName = (char *)malloc(256 *sizeof(char));
DWORD strSize = sizeof(computerName);
if (computerName == NULL) {
// 内存分配失败
SetText(RED);
printf(
"[Fatal] in %s, line %d, the function %s, the variable %s's memory not allocated correctly\n",
__FILE__,__LINE__,"MyGetComputerName(char*)","computerName(char*)"
);
SetText(WHITE);
return NULL;
}
if (GetComputerName(computerName, &strSize)) {
return computerName;
} else {
SetText(RED);
printf(
"[Fatal] in %s, line %d, the function %s, the variable %s's value not assignment correctly\n",
__FILE__,__LINE__,"MyGetComputerName(char*)","computerName(char*)"
);
SetText(WHITE);
return NULL;
}
}
|