RegEnumValue() question...

This is a discussion on RegEnumValue() question... within the Windows Programming forums, part of the Platform Specific Boards category; with the RegEnumValue() function can I get both value name and value data , or just the value name , ...

  1. #1
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768

    RegEnumValue() question...

    with the RegEnumValue() function can I get both value name and value data, or just the value name, and then use RegQueryValueEx() to get the value data...

    Because I'm trying to get the value data but I keep getting an empty string:

    Code:
    DWORD lnt=100;
    LPBYTE value_name[100]={0}, value_data[100]={0};
    
    if (RegEnumValue(reg_key, 0, value_name, &lnt, NULL, NULL, value_data, &lnt)!=ERROR_NO_MORE_ITEMS) {
        MessageBox(hwnd, value_name, "", 0);
        MessageBox(hwnd, value_data, "", 0);
    }
    The value_name returns fine, but the value_data is empty.


    Please help, thank you.
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Make sure you've allocated enough memory for the data. What is the value of lnt after the call to the API?

    Kuphryn

  3. #3
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    As a general rule, never use the same pointer value for two non-const pointer arguments to the one function.

    Consider a hypothetical implementation of RegEnumValue:
    Code:
    ...
    
    if (*lpcValueName > lstrlen(internal_value_name)
    {
        lstrcpy(lpValueName, internal_value_name);
        *lpcValueName = lstrlen(internal_value_name);
    }
    else
    {
        return ERROR_MORE_DATA;
    }
    
    if (*lpcbData > internal_data_size)
    {
        memcpy(lpData, internal_data, internal_data_size);
        *lpcbData = internal_data_size;
    }
    else
    {
        return ERROR_MORE_DATA;
    }
    
    ...
    Now why wouldn't this work if you supply the address of the same variable for both lpcValueName and lpcbData?

    Also, you should remember that not all registry values are strings and registry strings are not guaranteed to be nul terminated.

  4. #4
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768
    i didn't notice i used the same pointer
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 02:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 12:47 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21