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. Funny symbols Reading Registry Key Values

Funny symbols Reading Registry Key Values

Scheduled Pinned Locked Moved C / C++ / MFC
c++windows-admin
9 Posts 3 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
    J_E_D_I
    wrote on last edited by
    #1

    I am writing a code in C++ to read out a Registry key Value. The program runs with no errors but instead of reading the value either shows nothing (in case value == 0) or shows funny face symbols :sigh: :omg: ;P (if value == 1 or other values). Once this value is read I would also need to assign it to a variable. Any solution would be highly appreaciated! ///// code ///// HKEY MyKey; unsigned long type=REG_SZ, size=1024; char res[1024]=""; RegOpenKeyEx (HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones\\3\0", 0, KEY_READ, &MyKey); RegQueryValueEx (MyKey, "1400\0", NULL, &type, (LPBYTE)&res[0], &size); cout << "Ant the value is.....: " << *(LPBYTE)&res[0] << endl; RegCloseKey (MyKey); ///////////////////

    D 1 Reply Last reply
    0
    • J J_E_D_I

      I am writing a code in C++ to read out a Registry key Value. The program runs with no errors but instead of reading the value either shows nothing (in case value == 0) or shows funny face symbols :sigh: :omg: ;P (if value == 1 or other values). Once this value is read I would also need to assign it to a variable. Any solution would be highly appreaciated! ///// code ///// HKEY MyKey; unsigned long type=REG_SZ, size=1024; char res[1024]=""; RegOpenKeyEx (HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones\\3\0", 0, KEY_READ, &MyKey); RegQueryValueEx (MyKey, "1400\0", NULL, &type, (LPBYTE)&res[0], &size); cout << "Ant the value is.....: " << *(LPBYTE)&res[0] << endl; RegCloseKey (MyKey); ///////////////////

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      Why are you unnecessarily adding \0 to the string literals.

      J_E_D_I wrote:

      RegQueryValueEx (MyKey, "1400\0", NULL, &type, (LPBYTE)&res[0], &size);

      Why are you not reading this into a DWORD type?

      "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

      "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

      M J 3 Replies Last reply
      0
      • D David Crow

        Why are you unnecessarily adding \0 to the string literals.

        J_E_D_I wrote:

        RegQueryValueEx (MyKey, "1400\0", NULL, &type, (LPBYTE)&res[0], &size);

        Why are you not reading this into a DWORD type?

        "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

        "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

        M Offline
        M Offline
        Mark Salsbery
        wrote on last edited by
        #3

        How the heck did you determine it should be a DWORD from that code??? I'm way more curious about the LPBYTE cast when displaying the "string"... Mark

        Mark Salsbery Microsoft MVP - Visual C++ :java:

        1 Reply Last reply
        0
        • D David Crow

          Why are you unnecessarily adding \0 to the string literals.

          J_E_D_I wrote:

          RegQueryValueEx (MyKey, "1400\0", NULL, &type, (LPBYTE)&res[0], &size);

          Why are you not reading this into a DWORD type?

          "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

          "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

          M Offline
          M Offline
          Mark Salsbery
          wrote on last edited by
          #4

          Ahh now I see it (the DWORD) in the registry :rolleyes:

          Mark Salsbery Microsoft MVP - Visual C++ :java:

          1 Reply Last reply
          0
          • D David Crow

            Why are you unnecessarily adding \0 to the string literals.

            J_E_D_I wrote:

            RegQueryValueEx (MyKey, "1400\0", NULL, &type, (LPBYTE)&res[0], &size);

            Why are you not reading this into a DWORD type?

            "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

            "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

            J Offline
            J Offline
            J_E_D_I
            wrote on last edited by
            #5

            (I swear yesterday I saw my message succesfully posted on the website, but today I can't find it anymore! So I'm posting it again). David, I followed your advice and tried to read it into a DWORD type, but still it doesn't seem to work. What am I doing wrong? Besides reading the registry value, I need to assign it to a variable. Help please! HKEY MyKey; DWORD dwLen = sizeof(DWORD); DWORD dwKeyEn = 0; RegOpenKeyEx (HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones\\3", 0, KEY_READ, &MyKey); RegQueryValueEx(hKey, "1400", NULL, NULL,(LPBYTE)&KeyEn, &dwLen); cout << "And the value is.....: " << *(LPBYTE)&KeyEn << endl; RegCloseKey (MyKey);

            D 1 Reply Last reply
            0
            • J J_E_D_I

              (I swear yesterday I saw my message succesfully posted on the website, but today I can't find it anymore! So I'm posting it again). David, I followed your advice and tried to read it into a DWORD type, but still it doesn't seem to work. What am I doing wrong? Besides reading the registry value, I need to assign it to a variable. Help please! HKEY MyKey; DWORD dwLen = sizeof(DWORD); DWORD dwKeyEn = 0; RegOpenKeyEx (HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones\\3", 0, KEY_READ, &MyKey); RegQueryValueEx(hKey, "1400", NULL, NULL,(LPBYTE)&KeyEn, &dwLen); cout << "And the value is.....: " << *(LPBYTE)&KeyEn << endl; RegCloseKey (MyKey);

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #6

              J_E_D_I wrote:

              (I swear yesterday I saw my message succesfully posted on the website, but today I can't find it anymore! So I'm posting it again).

              The search feature is sometimes cantankerous.

              J_E_D_I wrote:

              RegQueryValueEx(hKey, "1400", NULL, NULL,(LPBYTE)&KeyEn, &dwLen); cout << "And the value is.....: " << *(LPBYTE)&KeyEn << endl;

              Should probably be:

              RegQueryValueEx(hKey, "1400", NULL, NULL, (LPBYTE)&dwKeyEn, &dwLen);
              cout << "And the value is.....: " << dwKeyEn << endl;

              "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

              "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

              J 1 Reply Last reply
              0
              • D David Crow

                J_E_D_I wrote:

                (I swear yesterday I saw my message succesfully posted on the website, but today I can't find it anymore! So I'm posting it again).

                The search feature is sometimes cantankerous.

                J_E_D_I wrote:

                RegQueryValueEx(hKey, "1400", NULL, NULL,(LPBYTE)&KeyEn, &dwLen); cout << "And the value is.....: " << *(LPBYTE)&KeyEn << endl;

                Should probably be:

                RegQueryValueEx(hKey, "1400", NULL, NULL, (LPBYTE)&dwKeyEn, &dwLen);
                cout << "And the value is.....: " << dwKeyEn << endl;

                "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

                "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                J Offline
                J Offline
                J_E_D_I
                wrote on last edited by
                #7

                With your modifications it doesn't show the funny symbols anymore..but it always returns "0" (as defined above by "DWORD dwKeyEn = 0", I guess) rather than reading the actual value from the registry. :~

                D 1 Reply Last reply
                0
                • J J_E_D_I

                  With your modifications it doesn't show the funny symbols anymore..but it always returns "0" (as defined above by "DWORD dwKeyEn = 0", I guess) rather than reading the actual value from the registry. :~

                  D Offline
                  D Offline
                  David Crow
                  wrote on last edited by
                  #8

                  So does HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3\1400 actually exist, and does it have a non-zero value? I tried this on my machine and it worked fine. You might verify that the last argument to RegOpenKeyEx() and the first argument to RegQueryValueEx() have the same value.

                  "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

                  "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                  J 1 Reply Last reply
                  0
                  • D David Crow

                    So does HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3\1400 actually exist, and does it have a non-zero value? I tried this on my machine and it worked fine. You might verify that the last argument to RegOpenKeyEx() and the first argument to RegQueryValueEx() have the same value.

                    "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

                    "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                    J Offline
                    J Offline
                    J_E_D_I
                    wrote on last edited by
                    #9

                    :-D :-D Wonderful, it works! I'm very grateful for your help. Send me a picture...and I'll make you a statue! How silly, I made a typing mistake writing hKey rather than MyKey in RegOpenKeyEx().

                    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