Solved

RegEnumKeyEx

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared 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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

828 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