Click here to Skip to main content
15,912,329 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: CSimpleDate and Visual Studio 2010 Pin
Chris Losinger16-Nov-11 4:54
professionalChris Losinger16-Nov-11 4:54 
SuggestionRe: CSimpleDate and Visual Studio 2010 Pin
David Crow16-Nov-11 5:03
David Crow16-Nov-11 5:03 
AnswerRe: CSimpleDate and Visual Studio 2010 Pin
Maximilien16-Nov-11 8:59
Maximilien16-Nov-11 8:59 
AnswerRe: CSimpleDate and Visual Studio 2010 Pin
xyloweb25-Nov-11 9:09
xyloweb25-Nov-11 9:09 
SuggestionCollaborated Tool/Library development Pin
BrainlessLabs.com15-Nov-11 22:59
BrainlessLabs.com15-Nov-11 22:59 
GeneralRe: Collaborated Tool/Library development Pin
Richard MacCutchan15-Nov-11 23:51
mveRichard MacCutchan15-Nov-11 23:51 
GeneralRe: Collaborated Tool/Library development Pin
BrainlessLabs.com16-Nov-11 6:53
BrainlessLabs.com16-Nov-11 6:53 
QuestionEnumerating Registry Subkeys c++ Pin
Member 824522215-Nov-11 20:06
Member 824522215-Nov-11 20:06 
from msdn.microsoft.com - Enumerating Registry Subkeys:

http://msdn.microsoft.com/En-US/library/ms724256.aspx

C++
// QueryKey - Enumerates the subkeys of key and its associated values.
//     hKey - Key whose subkeys and values are to be enumerated.

#include <windows.h>
#include <stdio.h>
#include <tchar.h>

#define MAX_KEY_LENGTH 255
#define MAX_VALUE_NAME 16383

void QueryKey(HKEY hKey) 
{ 
    TCHAR    achKey[MAX_KEY_LENGTH];   // buffer for subkey name
    DWORD    cbName;                   // size of name string 
    TCHAR    achClass[MAX_PATH] = TEXT("");  // buffer for class name 
    DWORD    cchClassName = MAX_PATH;  // size of class string 
    DWORD    cSubKeys=0;               // number of subkeys 
    DWORD    cbMaxSubKey;              // longest subkey size 
    DWORD    cchMaxClass;              // longest class string 
    DWORD    cValues;              // number of values for key 
    DWORD    cchMaxValue;          // longest value name 
    DWORD    cbMaxValueData;       // longest value data 
    DWORD    cbSecurityDescriptor; // size of security descriptor 
    FILETIME ftLastWriteTime;      // last write time 

    DWORD i, retCode; 

    TCHAR  achValue[MAX_VALUE_NAME]; 
    DWORD cchValue = MAX_VALUE_NAME; 

    // Get the class name and the value count. 
    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);
            }
        }
    } 

    // Enumerate the key values. 

    if (cValues) 
    {
        printf( "\nNumber of values: %d\n", cValues);

        for (i=0, retCode=ERROR_SUCCESS; i<cValues; i++) 
        { 
            cchValue = MAX_VALUE_NAME; 
            achValue[0] = '\0'; 
            retCode = RegEnumValue(hKey, i, 
                achValue, 
                &cchValue, 
                NULL, 
                NULL,
                NULL,
                NULL);

            if (retCode == ERROR_SUCCESS ) 
            { 
                _tprintf(TEXT("(%d) %s\n"), i+1, achValue); 
            } 
        }
    }
}

void __cdecl _tmain(void)
{
   HKEY hTestKey;

   if( RegOpenKeyEx( HKEY_CURRENT_USER,
        TEXT("SOFTWARE\\Microsoft"),
        0,
        KEY_READ,
        &hTestKey) == ERROR_SUCCESS
      )
   {
      QueryKey(hTestKey);
   }

   RegCloseKey(hTestKey);
}


how can i modify that code at:

C++
cchValue = MAX_VALUE_NAME; 
            achValue[0] = '\0'; 
            retCode = RegEnumValue(hKey, i, 
                achValue, 
                &cchValue, 
                NULL, 
                NULL,
                NULL,
                NULL);

            if (retCode == ERROR_SUCCESS ) 
            { 
                _tprintf(TEXT("(%d) %s\n"), i+1, achValue); 
            } 


to output to the console all the values that RegEnumValue function can return, function at msdn: http://msdn.microsoft.com/en-us/library/windows/desktop/ms724865%28v=vs.85%29.aspx i want to output these vars too:

C++
__out        LPTSTR lpValueName,
__inout      LPDWORD lpcchValueName,
__out_opt    LPDWORD lpType,
__out_opt    LPBYTE lpData,
__inout_opt  LPDWORD lpcbData


i have tried different things but everytime i change any of NULL var from that function:

C++
retCode = RegEnumValue(hKey, i, achValue, &cchValue, NULL, NULL, NULL, NULL);


i even don´t get achValue

thanks a lot

PD using windows 7 64 bits visual studio 2010 ultimate
AnswerRe: Enumerating Registry Subkeys c++ Pin
Richard MacCutchan15-Nov-11 22:09
mveRichard MacCutchan15-Nov-11 22:09 
AnswerRe: Enumerating Registry Subkeys c++ Pin
User 742933815-Nov-11 22:14
professionalUser 742933815-Nov-11 22:14 
GeneralRe: Enumerating Registry Subkeys c++ Pin
Richard MacCutchan15-Nov-11 23:55
mveRichard MacCutchan15-Nov-11 23:55 
Questionsimple static library linking to dll issue. Pin
Android Lava15-Nov-11 16:32
Android Lava15-Nov-11 16:32 
AnswerRe: simple static library linking to dll issue. Pin
Richard MacCutchan15-Nov-11 22:04
mveRichard MacCutchan15-Nov-11 22:04 
AnswerRe: simple static library linking to dll issue. Pin
Chuck O'Toole16-Nov-11 5:41
Chuck O'Toole16-Nov-11 5:41 
AnswerRe: simple static library linking to dll issue. Pin
jschell16-Nov-11 10:00
jschell16-Nov-11 10:00 
QuestionURLDownloadToFile, Cancel Button Pin
jkirkerx15-Nov-11 15:09
professionaljkirkerx15-Nov-11 15:09 
AnswerRe: URLDownloadToFile, Cancel Button Pin
Chuck O'Toole15-Nov-11 16:19
Chuck O'Toole15-Nov-11 16:19 
GeneralRe: URLDownloadToFile, Cancel Button Pin
jkirkerx15-Nov-11 16:32
professionaljkirkerx15-Nov-11 16:32 
AnswerRe: URLDownloadToFile, Cancel Button Pin
Chuck O'Toole15-Nov-11 17:01
Chuck O'Toole15-Nov-11 17:01 
GeneralRe: URLDownloadToFile, Cancel Button Pin
jkirkerx15-Nov-11 17:19
professionaljkirkerx15-Nov-11 17:19 
GeneralRe: URLDownloadToFile, Cancel Button Pin
jkirkerx16-Nov-11 11:01
professionaljkirkerx16-Nov-11 11:01 
GeneralRe: URLDownloadToFile, Cancel Button Pin
enhzflep16-Nov-11 13:40
enhzflep16-Nov-11 13:40 
GeneralRe: URLDownloadToFile, Cancel Button Pin
jkirkerx17-Nov-11 6:15
professionaljkirkerx17-Nov-11 6:15 
GeneralRe: URLDownloadToFile, Cancel Button Pin
enhzflep17-Nov-11 19:45
enhzflep17-Nov-11 19:45 
GeneralRe: URLDownloadToFile, Cancel Button Pin
jkirkerx18-Nov-11 6:33
professionaljkirkerx18-Nov-11 6:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.