Reduced the code a little so I could test it in my environment:
PHP Code:
#define MAX_KEY_LENGTH 4096
#define MAX_VALUE_NAME 4096
#define MAX_KEY_LENGTH 4096
void RegistryCleaner::querykey(HKEY hk, const char *k, FILE* fh)
{
char szBuffer[MAX_KEY_LENGTH];
HKEY hKey;
RegOpenKeyEx(hk, k, 0, KEY_ALL_ACCESS, &hKey);
DWORD cSubKeys;
DWORD maxSubkeyLen;
DWORD retCode;
RegQueryInfoKey(hKey, NULL, NULL, NULL, &cSubKeys, &maxSubkeyLen, NULL, NULL, NULL, NULL, NULL, NULL);
if(cSubKeys > 0)
{
static char currentSubkey[MAX_PATH];
int i;
for(i = 0; i < cSubKeys; i++)
{
DWORD currentSubLen=MAX_PATH;
retCode = RegEnumKeyEx(hKey, i, currentSubkey, ¤tSubLen, NULL, NULL, NULL, NULL);
if(retCode == ERROR_SUCCESS)
{
char l[3 * MAX_KEY_LENGTH];
sprintf(l, "%s\\%s", k, currentSubkey);
printf("%s\\%s\n", k, currentSubkey);
fputs(l, fh);
fputs("\r\n", fh);
querykey(hk, l, fh);
}
}
}
RegCloseKey(hKey);
}
Called it with the following:
PHP Code:
RegistryCleaner* cleaner = new RegistryCleaner();
FILE* fh = fopen("C:\\enum.txt", "a+");
cleaner->querykey(HKEY_CURRENT_USER, "Software", fh);
And that worked fine as I'd get a nice list of all the subkeys of Software.
Problem with your code is in the recursion.
At some point your function will be called with "Software\2015" and it will print "Software\2015\MOHAA" to your Window as that's the only subkey. And because that's the deepest it can go, it will "go all the way back" to "Software". Then it will (for example) go into "7-Zip". Problem is that it will just print "Software\7-Zip" to your Window and overwrite any previously printed text as it has no knowledge of any previous calls.
It would thus be better to append to your Window's Text instead of just Setting it.
By that I mean this call:
PHP Code:
SetWindowText(hTest, szBuffer);
Should be something like:
PHP Code:
char currentText[MAX_KEY_LENGTH];
GetWindowText(hTest, currentText, MAX_KEY_LENGTH);
strcat(currentText, szBuffer);
SetWindowText(hTest, currentText);
MAX_KEY_LENGTH should probably be something else though.