Solved

RegEnumKeyEx

Posted on 1999-01-09
2
515 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
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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 …
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now