My registry won't register
-
Perhaps some kind soul out there can see what I'm doing wrong here: The following code tries to get some registry values. UCHAR ServerIP[ 16 ], ServerToPort[ 16 ], ServerFromPort[ 16 ]; UCHAR LocalIP[ 16 ], LocalToPort[ 16 ], LocalFromPort[ 16 ]; HKEY key1, key2; DWORD disp, type, size; LONG result; // Open the company key result = RegCreateKeyEx( HKEY_CURRENT_USER, "UHS", 0, "", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &key1, &disp ); // Open the Local subkey result = RegCreateKeyEx( key1, "Local", 0, "", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &key2, &disp ); // Get the values of IP, InPort, OutPort result = RegQueryValueEx( key2, "IP", 0, &type, LocalIP, &size ); + result = RegQueryValueEx( key2, "ToPort", 0, &type, LocalToPort, &size ); + result = RegQueryValueEx( key2, "FromPort", 0, &type, LocalFromPort, &size ); // Open the Server subkey result = RegCreateKeyEx( key1, "Server", 0, "", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &key2, &disp ); // Get the values of IP, InPort, OutPort ? result = RegQueryValueEx( key2, "IP", 0, &type, ServerIP, &size ); result = RegQueryValueEx( key2, "ToPort", 0, &type, ServerToPort, &size ); result = RegQueryValueEx( key2, "FromPort", 0, &type, ServerFromPort, &size ); The registry entries are just IPs and port numbers and the editor shows they are OK. When the above code is run it fills in everything EXCEPT ServerIP. This call returns an error "234" which the ISDN helpfully identifies as "More data available". If I leave out the two calls marked with "+" the thing works and I get the ServerIP. I have tried to change the order of calling things but no matter what I do, one of the values returns an error. I have tried all kinds of other things like having individual key handles, flushing etc. but nothing works. My registry is not corrupt and I have tried this on two different machines in different offices. Hope someone knows what's happening.
-
Perhaps some kind soul out there can see what I'm doing wrong here: The following code tries to get some registry values. UCHAR ServerIP[ 16 ], ServerToPort[ 16 ], ServerFromPort[ 16 ]; UCHAR LocalIP[ 16 ], LocalToPort[ 16 ], LocalFromPort[ 16 ]; HKEY key1, key2; DWORD disp, type, size; LONG result; // Open the company key result = RegCreateKeyEx( HKEY_CURRENT_USER, "UHS", 0, "", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &key1, &disp ); // Open the Local subkey result = RegCreateKeyEx( key1, "Local", 0, "", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &key2, &disp ); // Get the values of IP, InPort, OutPort result = RegQueryValueEx( key2, "IP", 0, &type, LocalIP, &size ); + result = RegQueryValueEx( key2, "ToPort", 0, &type, LocalToPort, &size ); + result = RegQueryValueEx( key2, "FromPort", 0, &type, LocalFromPort, &size ); // Open the Server subkey result = RegCreateKeyEx( key1, "Server", 0, "", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &key2, &disp ); // Get the values of IP, InPort, OutPort ? result = RegQueryValueEx( key2, "IP", 0, &type, ServerIP, &size ); result = RegQueryValueEx( key2, "ToPort", 0, &type, ServerToPort, &size ); result = RegQueryValueEx( key2, "FromPort", 0, &type, ServerFromPort, &size ); The registry entries are just IPs and port numbers and the editor shows they are OK. When the above code is run it fills in everything EXCEPT ServerIP. This call returns an error "234" which the ISDN helpfully identifies as "More data available". If I leave out the two calls marked with "+" the thing works and I get the ServerIP. I have tried to change the order of calling things but no matter what I do, one of the values returns an error. I have tried all kinds of other things like having individual key handles, flushing etc. but nothing works. My registry is not corrupt and I have tried this on two different machines in different offices. Hope someone knows what's happening.
You should initialize size parameter before calling RegQueryValueEx - on input it should contain size of the buffer provided by the caller:
size = sizeof(ServerIP);
result = RegQueryValueEx( key2, "IP", 0, &type, ServerIP, &size );This applies to all RegQueryValueEx calls, not only ServerIP. Tomasz Sowinski -- http://www.shooltz.com.pl
-
You should initialize size parameter before calling RegQueryValueEx - on input it should contain size of the buffer provided by the caller:
size = sizeof(ServerIP);
result = RegQueryValueEx( key2, "IP", 0, &type, ServerIP, &size );This applies to all RegQueryValueEx calls, not only ServerIP. Tomasz Sowinski -- http://www.shooltz.com.pl
You are an angel of mercy. It works!!! Thank you. (Lesson for others: Don't be stupid like me. Read the MSDN parameter doco very carefuly.)