如果我想使用 RegGetValue 从注册表中读取变量字符串,这样做是一种好习惯吗?
DWORD dwByteCount=20,dwType;
char *value = (char *)malloc(dwByteCount);
HKEY hKey;
LONG lResult;
while(TRUE){
lResult = RegGetValue(hKey,
"somesubkey",
"somevalue",
RRF_RT_REG_SZ,
&dwType,
value,
&dwBytesAllocated);
if(lResult == ERROR_SUCCESS){
break;
}
else if(lResult == ERROR_MORE_DATA){
free(value);
dwBytesAllocated+=20;
value = (char *)malloc(dwBytesAllocated);
}
else {
free(value);
return NULL;
}
}