Solved

RegEnumKeyEx

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

Suggested Solutions

Title # Comments Views Activity
Microsoft Query from QuickBooks 9 75
Example of WebAPI 7 35
Need an intro to -- .Net SQL Authorization Manager 7 95
Infrastructure development vs software development 3 80
This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
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…

749 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