Link to home
Start Free TrialLog in
Avatar of JoeBurwell
JoeBurwell

asked on

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!
ASKER CERTIFIED SOLUTION
Avatar of jhance
jhance

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of fstab
fstab

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 ..
Avatar of JoeBurwell

ASKER

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!
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...