Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ERROR_MORE_DATA

Status
Not open for further replies.

mleelun

Programmer
Sep 29, 2003
2
US
Has anyone seen RegEnumValue return ERROR_MORE_DATA even though the buffer is adequate? I am recursively calling this function to get info from the registry and it works for 99% of the tree. However, I get this error for some keys.

Mike
 
>> even though the buffer is adequate?

How about the buffer size argument?

Is the problem consistent? If so can you provide a specific case?


-pete
 
HKLM\SOFTWARE\Classes\AIFFFile\FriendlyTypeName

It returns ERROR_MORE_DATA, but if I print the value out anyway it returns the value...

Here is the code:

int PrintRegKey(HKEY hKey, HKEY szHKEY, char *RegistryLine, char *szRegistryKey)
{
DWORD items = 0;
DWORD buffersizeentry = 0;
DWORD buffersizevalue = 0;
DWORD buffersizesubkey = 0;
DWORD DataType = 0;
TCHAR szRegistryEntry[MAX_PATH + 1];
TCHAR szRegistryValue1[MAX_PATH + 1];
TCHAR szRegistrySubKey[MAX_PATH + 1];

// printf("%s %s\n", szRegistryKey, RegistryLine);
buffersizevalue = sizeof(szRegistryValue1);
buffersizeentry = sizeof(szRegistryEntry);
// RegQueryInfoKey(hKey, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &buffersizevalue, &buffersizeentry, NULL, NULL);
// buffersizevalue++;
// buffersizeentry++;
long test = RegEnumValue(hKey, items, szRegistryValue1, &buffersizevalue, 0, &DataType, (LPBYTE) &szRegistryEntry, &buffersizeentry);
while (test != ERROR_NO_MORE_ITEMS)
{
if (1 != 1)
{
fprintf(fErrorLog, "Buffer size inadequate for attribute in key: %s %s %i %i\n", szRegistryKey, szRegistryEntry, buffersizevalue, buffersizeentry);
}
else
{
if (test == ERROR_MORE_DATA)
{
fprintf(fErrorLog, "Buffer size inadequate for attribute in key: %s %s %i %i\n", szRegistryKey, szRegistryEntry, buffersizevalue, buffersizeentry);
fprintf(fOut, "ERROR_MORE_DATA\n");
}
buffersizevalue = sizeof(szRegistryValue1);
buffersizeentry = sizeof(szRegistryEntry);
switch(DataType)
{
case (REG_BINARY):
{
fprintf(fOut, "%s;%s\\%s\\%s;", HOSTNAME, RegistryLine, szRegistryKey, szRegistryValue1);
RegQueryValueEx(hKey, szRegistryValue1, NULL, NULL, NULL, &buffersizeentry);
for (DWORD i = 0; i < buffersizeentry; i++)
{
fprintf(fOut, &quot;%02x &quot;, szRegistryEntry & 255);
}
fprintf(fOut, &quot;\n&quot;);
break;
}
case (REG_DWORD):
{
fprintf(fOut, &quot;%s;%s\\%s\\%s;%x\n&quot;, HOSTNAME, RegistryLine, szRegistryKey, szRegistryValue1, *szRegistryEntry);
break;
}
case (REG_EXPAND_SZ):
{
fprintf(fOut, &quot;%s;%s\\%s\\%s;%s\n&quot;, HOSTNAME, RegistryLine, szRegistryKey, szRegistryValue1, szRegistryEntry);
break;
}
case (REG_MULTI_SZ):
{
char *pointer = szRegistryEntry;
while (pointer[0] != '\0')
{
fprintf(fOut, &quot;%s;%s\\%s\\%s;%s\n&quot;, HOSTNAME, RegistryLine, szRegistryKey, szRegistryValue1, pointer);
while (pointer[0] != '\0') pointer++;
pointer++;
}
break;
}
case (REG_SZ):
{
fprintf(fOut, &quot;%s;%s\\%s\\%s;%s\n&quot;, HOSTNAME, RegistryLine, szRegistryKey, szRegistryValue1, szRegistryEntry);
break;
}
case (REG_LINK):
case (REG_NONE):
//case (REG_DWORD_LITTLE_ENDIAN):
//case (REG_DWORD_BIG_ENDIAN):
//case (REG_QWORD):
//case (REG_QWORD_LITTLE_ENDIAN):
default: break;
}
}
items++;
test = RegEnumValue(hKey, items, szRegistryValue1, &buffersizevalue, 0, &DataType, (LPBYTE) &szRegistryEntry, &buffersizeentry);
}
items = 0;
buffersizesubkey = sizeof(szRegistrySubKey);
while (RegEnumKey(hKey, items, szRegistrySubKey, buffersizesubkey) == ERROR_SUCCESS)
{
buffersizesubkey = sizeof(szRegistrySubKey);
//printf(&quot;%s\\%s\\%s\n&quot;, RegistryLine, szRegistryKey, szRegistrySubKey);
items++;
char *newkey = (char *) malloc (strlen(szRegistryKey) + strlen(szRegistrySubKey) + 2);
HKEY newHKEY;
strcpy(newkey, szRegistryKey);
strcat(newkey, &quot;\\&quot;);
strcat(newkey, szRegistrySubKey);
if (RegOpenKeyEx(szHKEY, newkey, 0, KEY_READ, &newHKEY) == ERROR_SUCCESS)
{
PrintRegKey(newHKEY, szHKEY, RegistryLine, newkey);
free(newkey);
RegCloseKey(newHKEY);
}
}
return 0;
}

int ReadReg(char *RegistryLine)
{
HKEY hKey;
HKEY szHKEY;
DWORD buffersizeentry = 0;
DWORD buffersizevalue = 0;
DWORD buffersizesubkey = 0;
DWORD DataType = 0;
TCHAR szRegistryEntry[MAX_PATH + 1];
// TCHAR szRegistryValue1[MAX_PATH + 1];
// TCHAR szRegistrySubKey[MAX_PATH + 1];
LPTSTR szRegistryKey = (LPTSTR) malloc (256);
LPTSTR szRegistryValue = (LPTSTR) malloc (256);
//LPTSTR szRegistryValueEnum;
szRegistryKey = strchr(RegistryLine, '\\') + 1;
szRegistryValue = strrchr(RegistryLine, '\\') + 1;
szRegistryKey[strlen(szRegistryKey) - strlen(szRegistryValue) - 1] = '\0';
RegistryLine[strlen(RegistryLine) - strlen(szRegistryKey) - 1] = '\0';

if (strcmp(RegistryLine, &quot;HKEY_CLASSES_ROOT&quot;) == 0) szHKEY = HKEY_CLASSES_ROOT;
if (strcmp(RegistryLine, &quot;HKEY_CURRENT_USER&quot;) == 0) szHKEY = HKEY_CURRENT_USER;
if (strcmp(RegistryLine, &quot;HKEY_LOCAL_MACHINE&quot;) == 0) szHKEY = HKEY_LOCAL_MACHINE;
if (strcmp(RegistryLine, &quot;HKEY_USERS&quot;) == 0) szHKEY = HKEY_USERS;
if (strcmp(RegistryLine, &quot;HKEY_CURRENT_CONFIG&quot;) == 0) szHKEY = HKEY_CURRENT_CONFIG;

if (RegOpenKeyEx(szHKEY, szRegistryKey, 0, KEY_READ, &hKey) == ERROR_SUCCESS)
{
if (strcmp(szRegistryValue, &quot;*&quot;) == 0)
{
PrintRegKey(hKey, szHKEY, RegistryLine, szRegistryKey);
}
else
{
buffersizeentry = sizeof(szRegistryEntry);
if (RegQueryValueEx(hKey, szRegistryValue, 0, &DataType, (LPBYTE) &szRegistryEntry, &buffersizeentry) == ERROR_SUCCESS)
{
fprintf(fOut, &quot;%s;%s\\%s\\%s;%s\n&quot;, HOSTNAME, RegistryLine, szRegistryKey, szRegistryValue, szRegistryEntry);
}
else
{
fprintf(fErrorLog, &quot;Error getting attibute for %s\\%s\\%s\n&quot;, RegistryLine, szRegistryKey, szRegistryValue);
}
}
}
else
{
fprintf(fErrorLog, &quot;Error opening key: %s\\%s\\%s\n&quot;, RegistryLine, szRegistryKey, szRegistryValue);
}
return 0;
}
 
You should also post code between TGML code tags. Instructions for doing this are directly beneath the edit window you type your Tek-Tips post into.

Also, when you post code it should be the smallest possible amount to produce the problem. This needs to be accompanied with specific execution time values representing the problem. This type of information is necessary to provide context since we can’t observe the problem first hand. We are therefore dependent on you to post relevant information.


-pete
 
>even though the buffer is adequate
after each reading (RegQueryValueEx) of a registry value buffersizeentry is changed to the size of last read number of bytes. So you should set again this value before using it in a new RegQueryValueEx

Ion Filipski
1c.bmp

ICQ: 95034075
AIM: IonFilipski
filipski@excite.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top