Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6634915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:59:13+00:00 2026-05-25T22:59:13+00:00

I’m making an application, and i need to write some stuff in the registry,

  • 0

I’m making an application, and i need to write some stuff in the registry, and later edit them if neccessary. I’m writing to the 64 bit registry using KEY_WOW64_64KEY. I created my Key Software\MyApp and here some other values 5 or 6. My problem is the following. I have the following code to read every values, under a key

void ReadAndDeleteValues( HKEY hKey )
{

//TCHAR    achKey[ MAX_KEY_LENGTH ];        // buffer for subkey name
//DWORD    cbName;                          // size of name string 
TCHAR    achClass[ MAX_PATH ] = TEXT("");   // buffer for class name 
DWORD    cchClassName = MAX_PATH;           // size of class string 
DWORD    cSubKeys=0;                        // number of subkeys 
DWORD    cbMaxSubKey;                       // longest subkey size 
DWORD    cchMaxClass;                       // longest class string 
DWORD    cValues;                           // number of values for key 
DWORD    cchMaxValue;                       // longest value name 
DWORD    cbMaxValueData;                    // longest value data 
DWORD    cbSecurityDescriptor;              // size of security descriptor 
FILETIME ftLastWriteTime;                   // last write time 

DWORD i, retCode; 

TCHAR  achValue[ MAX_VALUE_NAME ]; 
DWORD cchValue = MAX_VALUE_NAME; 

// Get the class name and the value count. 
retCode = RegQueryInfoKey(
                            hKey,                    // key handle 
                            achClass,                // buffer for class name 
                            &cchClassName,           // size of class string 
                            NULL,                    // reserved 
                            &cSubKeys,               // number of subkeys 
                            &cbMaxSubKey,            // longest subkey size 
                            &cchMaxClass,            // longest class string 
                            &cValues,                // number of values for this key 
                            &cchMaxValue,            // longest value name 
                            &cbMaxValueData,         // longest value data 
                            &cbSecurityDescriptor,   // security descriptor 
                            &ftLastWriteTime         // last write time 
                         );

if ( cValues > 0 ) printf( "\nNumber of values: %d\n", cValues );

for ( i = 0, retCode = ERROR_SUCCESS; i < cValues; i++ ) 
{ 
    cchValue = MAX_VALUE_NAME; 
    achValue[ 0 ] = '\0'; 

    retCode = RegEnumValue( hKey, 
                            i, 
                            achValue, 
                            &cchValue, 
                            NULL, 
                            NULL,
                            NULL,
                            NULL
                          );

    if ( retCode == ERROR_SUCCESS ) 
    { 

        DWORD cbData = 8192;
        DWORD dwRet;
        DWORD type = 0;
        wchar_t PerfData[ 2048 ] = { 0 };

        memset( PerfData, 0, wcslen( PerfData ) );

        dwRet = RegQueryValueEx( hKey,
                                 achValue,
                                 NULL,
                                 &type,
                                 ( LPBYTE )PerfData,
                                 &cbData 
                               );

        if ( dwRet == ERROR_SUCCESS ) ;//do nothing
        else printf( "\n\nRegQueryValueEx Failed!" );

        _tprintf( TEXT( "\n  #%.3d - [ %-30s ]" ), i + 1, achValue ); 

        RegDeleteValue( hKey, achValue );

    }//if
}//for

}//ReadValues

It works fine, so i thought, i just place RegDeleteValue there and every Value will be deleted. Unfortunately this is not what’s happening. This API will delete only 2-3 values, then returns. If i run it again, then it will delete 2-3 values again and returns again, but i don’t know why???? Theoratically if i a find a vale, i can delete, so i don’t understand, why is this happening.

Could someone help me correct my code?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T22:59:14+00:00Added an answer on May 25, 2026 at 10:59 pm

    Your program deletes only a few values because of the classic ‘deleting from array’ mistake, like in this pseudocode:

    // this program will not remove all elements
    for (int i = 0, n = arraySize; i < n; ++i)
        array_remove(array, i);
    
    // step 1, i=0: 1 2 3 4 5 6
    //              ^ removed
    // step 2, i=1: 2 3 4 5 6
    //                ^ removed
    // step 3, i=2: 2 4 5 6
    //                  ^ removed
    // step 4, i=3: 2 4 6
    //                    ^ RegEnumValue returns error and the loop exits
    

    A correct way will be something like:

    while (cValues > 0) {
        /* delete registry value at index 0 */
        --cValues;
    }
    

    To quickly fix your code, replace the second parameter of RegEnumValue() with 0.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have thousands of HTML files to process using Groovy/Java and I need to
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
In my XML file chapters tag has more chapter tag.i need to display chapters

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.