return registry subkeys values like vector TCHAR

This is a discussion on return registry subkeys values like vector TCHAR within the Windows Programming forums, part of the Platform Specific Boards category; i have this code to list [COLOR=#0000ff !important] [COLOR=#0000FF ! important] registry [COLOR=#0000FF ! important] key [/COLOR] [/COLOR][/COLOR] values and ...

  1. #1
    Registered User
    Join Date
    Apr 2012
    Posts
    1

    return registry subkeys values like vector TCHAR

    i have this code to list [COLOR=#0000ff !important][COLOR=#0000FF ! important]registry [COLOR=#0000FF ! important]key[/COLOR][/COLOR][/COLOR] values and subkeys


    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:
    Code:
    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 by thorbcn; 04-22-2012 at 04:49 AM.

  2. #2
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,649
    A TCHAR is a *single* character. You need a vector of LPTSTR, each of which you will need to allocate and populate in your loop.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. return values
    By Marlon in forum C++ Programming
    Replies: 17
    Last Post: 06-22-2005, 03:30 AM
  2. return values
    By C++Child in forum C++ Programming
    Replies: 5
    Last Post: 07-21-2004, 06:16 PM
  3. Reading Registry Values
    By phantomlord in forum Windows Programming
    Replies: 2
    Last Post: 10-09-2003, 02:09 PM
  4. Interesting Registry Stuff (Keys, Values, etc.)
    By civix in forum A Brief History of Cprogramming.com
    Replies: 9
    Last Post: 01-27-2003, 08:58 AM
  5. vector of pointers vs vector of values
    By Shadow12345 in forum C++ Programming
    Replies: 1
    Last Post: 12-07-2002, 01:27 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21