return registry subkeys values like vector TCHAR

i have this code to list registry key values and subkeys


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
TCHAR achKey[MAX_KEY_LENGTH]; // buffer for subkey name
retCode = RegQueryInfoKey(
hKey, // key handle
achClass, // buffer for class name
&cchClassName, // size of class string
NULL, // reserved
&cSubKeys, // number of subkeys
&cbMaxSubKey, // longest subkey size
&cchMaxClass, // longest class string
&cValues, // number of values for this key
&cchMaxValue, // longest value name
&cbMaxValueData, // longest value data
&cbSecurityDescriptor, // security descriptor
&ftLastWriteTime); // last write time

// Enumerate the subkeys, until RegEnumKeyEx fails.

if (cSubKeys)
{
printf( "\nNumber of subkeys: %d\n", cSubKeys);

for (i=0; i<cSubKeys; i++)
{
cbName = MAX_KEY_LENGTH;
retCode = RegEnumKeyEx(hKey, i,
achKey,
&cbName,
NULL,
NULL,
NULL,
&ftLastWriteTime);
if (retCode == ERROR_SUCCESS)
{
_tprintf(TEXT("(%d) %s\n"), i+1, achKey);
}
}
}
i want to return subkeys names like an array or vector of strings TCHAR,
i tried:
vector<TCHAR> getSubKeys(HKEY key)
{
    vector<TCHAR>> subkeys;
    ....
    for (i=0; i<cSubKeys; i++) 
    {
        // get subkey name
        subkeys.push_back(TCHAR(achKey));
    }
    ....
    return subkeys;
}

with this change it works but at t_main function when i try to list the vector to the console just show eight(the number of subkeys is correct) numbers like 65000 the same value for the eight vector elements, where's the problem or how can i compile with your code, thanks a lot
thanks a lot
Last edited on
Use code tags (http://cplusplus.com/articles/z13hAqkS/ ) so we can read properly formatted code. As it is now, i just won't read it.
Topic archived. No new replies allowed.