Solved

RegEnumKeyEx

Posted on 1999-01-09
2
542 Views
Last Modified: 2013-12-03
the code following returns 87 in the result variable after calling the RegEnumKetEx function. any ideas?

DWORD numSubKeys;
char* subKeyName;
DWORD dwName;

long result = RegQueryInfoKey(HKEY_LOCAL_MACHINE, NULL,NULL,            &numSubKeys, NULL,NULL,NULL,NULL,NULL,NULL,NULL);

if (result == ERROR_SUCCESS)
{
    for (unsigned int kCntr = 0; kCntr < numSubKeys; Cntr++)
    {
      result = RegEnumKeyEx(HKEY_LOCAL_MACHINE, kCntr,    subKeyName, &dwName, NULL, NULL, NULL, NULL);

      if (result == ERROR_SUCCESS)
      {
      m_Tree.InsertItem(subKeyName,1,1,root,TVI_LAST);
                  }
            }
      }
0
Comment
Question by:skarj
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 1

Author Comment

by:skarj
ID: 1418382
Edited text of question
0
 
LVL 86

Accepted Solution

by:
jkr earned 20 total points
ID: 1418383
The reasons for error 87 (aka. ERROR_INVALID_PARAMETER) are
1. you're using an uninitialized pointer as a buffer for the subkey
2. as you can see in the documentation, no parameter (except lpReserved) may be set to NULL

BTW: There's no reason to use 'RegEnumKeyEx()', the following code will do the same:

    HKEY        hKey    =   HKEY_LOCAL_MACHINE;
    int         nIdx    =   0;
    long        lnRes;

    char        acSubKey    [   WHATEVER_THE_SIZE_SHOULD_BE];

   
    for (   ;;)
        {
            lnRes   =   RegEnumKey  (   hKey,
                                        nIdx,
                                        acSubKey,
                                        sizeof  (   acSubKey)
                                    );

            if  (   ERROR_NO_MORE_ITEMS ==  lnRes)
                {  
                    break;
                }

            if  (   ERROR_SUCCESS   !=  lnRes)
                {
                    return  (   FALSE);
                }

            // do something with the key name in acSubKey

            nIdx++;
        }


0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question