• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 293
  • Last Modified:

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!
0
JoeBurwell
Asked:
JoeBurwell
  • 2
1 Solution
 
jhanceCommented:
You must reset the value of reg_buffer_size BEFORE each call to RegEnumValue.
0
 
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

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now