Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. My registry won't register

My registry won't register

Scheduled Pinned Locked Moved C / C++ / MFC
sysadminwindows-adminhelpquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Joe Moldovan
    wrote on last edited by
    #1

    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.

    T 1 Reply Last reply
    0
    • J Joe Moldovan

      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.

      T Offline
      T Offline
      Tomasz Sowinski
      wrote on last edited by
      #2

      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

      J 1 Reply Last reply
      0
      • T Tomasz Sowinski

        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

        J Offline
        J Offline
        Joe Moldovan
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups