Registry access => SERIALCOMM

I want my code to read the values in the registry key, "HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM".  I can open the key properly (with RegOpenKeyEx).  I then use the following code to read the contents until the "end":

while(enum_reg_status != ERROR_NO_MORE_ITEMS)
{
    enum_reg_status = RegEnumValue(nt_com_key, x, (char*)reg_name, &name_buffer_size, NULL, &reg_info_type, individual_reg_entry, &reg_buffer_size);

if(enum_reg_status != ERROR_MORE_DATA)
{
   break;
}

++x;
}

RegCloseKey(nt_com_key);
//*******************************
In this section of the registry I see 4 values (using Regedit): Default (no value set), "COM1", "COM2", and "COM3".  When I step through the above code, the RegEnumValue function returns with no error (the first time), but it doesn't update the variable, individual_reg_entry, with the data ("COM1", ...).  I do see (in the subsequent loops) "COM2" and "COM3", and I can store those values.
????
Why don't I see "COM1", but I see the other values?  (Note:  x is the index, and I set it to 0 before entering the loop.)
Thanks!
JoeBurwellAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jhanceCommented:
You must reset the value of reg_buffer_size BEFORE each call to RegEnumValue.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
fstabCommented:
Boy, jhance are you quick !! :-( I was just trying out the code on my PC and was about to give out this answer ..

Anyways I tried resetting name_buffer_size everytime and it worked fine ..
0
JoeBurwellAuthor Commented:
I modified my code as follows:

name_buffer_size = 100;
reg_buffer_size = 100;

while(enum_reg_status == ERROR_SUCCESS)
{
  enum_reg_status = RegEnumValue  (nt_com_key, x,
(char*)single_reg_name,
&name_buffer_size, NULL
&reg_info_type, individual_reg_entry,
&reg_buffer_size);

if(enum_reg_status != ERROR_SUCCESS)
{
  break;
}
// ...

++x;
reg_buffer_size = 100;
name_buffer_size = 100;
}// end while(enum_reg_status...)

That solved the problem!  Thanks!
0
jhanceCommented:
fstab,

I'd love to say it's because I'm so smart....but the truth is that I've been burned by this so many times that it's the FIRST thing I check with the registry functions don't work right...

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.