Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

RegEnumKeyEx

Posted on 1999-01-09
2
Medium Priority
?
552 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 80 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

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 …
If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
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: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

721 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