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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Problems Querying a registry value

Problems Querying a registry value

Scheduled Pinned Locked Moved C / C++ / MFC
helpdatabasewindows-adminquestion
6 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.
  • L Offline
    L Offline
    Luis E Cuadrado
    wrote on last edited by
    #1

    Hello Everybody ok, here is my code: HKEY keyHandle; char *rgValue = NULL; PLONG buffLen = NULL; if(RegOpenKey( HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion", &keyHandle) == ERROR_SUCCESS) { //MessageBox(_T("Key was opened")); RegQueryValue(keyHandle, "MediaPath", rgValue, buffLen ); MessageBox(rgValue); } What I want to do is to query the registry value of MediaPath and store it in the rgValue variable. I looked at it in MSDN and I did exactly that it says. I tryed a couple of times and nothing is being saved in rgValue. Have you guys had this problem before. What should I do? Am I missing something? Any anwer is more than welcome. Have a good day, Luis E. Cuadrado :0)

    T 1 Reply Last reply
    0
    • L Luis E Cuadrado

      Hello Everybody ok, here is my code: HKEY keyHandle; char *rgValue = NULL; PLONG buffLen = NULL; if(RegOpenKey( HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion", &keyHandle) == ERROR_SUCCESS) { //MessageBox(_T("Key was opened")); RegQueryValue(keyHandle, "MediaPath", rgValue, buffLen ); MessageBox(rgValue); } What I want to do is to query the registry value of MediaPath and store it in the rgValue variable. I looked at it in MSDN and I did exactly that it says. I tryed a couple of times and nothing is being saved in rgValue. Have you guys had this problem before. What should I do? Am I missing something? Any anwer is more than welcome. Have a good day, Luis E. Cuadrado :0)

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

      You need to initialize buffLen with an address of variable containing max size of buffer before calling RegQueryValue. Tomasz Sowinski -- http://www.shooltz.com

      Free your mind and your ass will follow.

      L 1 Reply Last reply
      0
      • T Tomasz Sowinski

        You need to initialize buffLen with an address of variable containing max size of buffer before calling RegQueryValue. Tomasz Sowinski -- http://www.shooltz.com

        Free your mind and your ass will follow.

        L Offline
        L Offline
        Luis E Cuadrado
        wrote on last edited by
        #3

        Hi Tomasz: Thank you for your quick reply. This is what I did to my code after reading your reply: HKEY keyHandle; char rgValue**[MAX_PATH];** DWORD buffLen = MAX_PATH; if(RegOpenKey( HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion", &keyHandle) == ERROR_SUCCESS) { //MessageBox(_T("Key was opened")); RegQueryValue(keyHandle, "MediaPath", rgValue, (PLONG) buffLen ); MessageBox(rgValue); } Is that what you meant by initializing buffLen? I'm new in MFC specially reading registry stuff, so I apologize for my ignorance. Luis E. Cuadrado :0)

        T L 2 Replies Last reply
        0
        • L Luis E Cuadrado

          Hi Tomasz: Thank you for your quick reply. This is what I did to my code after reading your reply: HKEY keyHandle; char rgValue**[MAX_PATH];** DWORD buffLen = MAX_PATH; if(RegOpenKey( HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion", &keyHandle) == ERROR_SUCCESS) { //MessageBox(_T("Key was opened")); RegQueryValue(keyHandle, "MediaPath", rgValue, (PLONG) buffLen ); MessageBox(rgValue); } Is that what you meant by initializing buffLen? I'm new in MFC specially reading registry stuff, so I apologize for my ignorance. Luis E. Cuadrado :0)

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

          It should work. BTW: 'registry stuff' you're using now isn't MFC, its plain Win32 API. Tomasz Sowinski -- http://www.shooltz.com

          Free your mind and your ass will follow.

          1 Reply Last reply
          0
          • L Luis E Cuadrado

            Hi Tomasz: Thank you for your quick reply. This is what I did to my code after reading your reply: HKEY keyHandle; char rgValue**[MAX_PATH];** DWORD buffLen = MAX_PATH; if(RegOpenKey( HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion", &keyHandle) == ERROR_SUCCESS) { //MessageBox(_T("Key was opened")); RegQueryValue(keyHandle, "MediaPath", rgValue, (PLONG) buffLen ); MessageBox(rgValue); } Is that what you meant by initializing buffLen? I'm new in MFC specially reading registry stuff, so I apologize for my ignorance. Luis E. Cuadrado :0)

            L Offline
            L Offline
            Le centriste
            wrote on last edited by
            #5

            Yes, that is what he meant, except for:

            LONG buffLen = MAX_PATH;
            RegQueryValue(keyHandle, "MediaPath", rgValue, &buffLen );

            Btw, you should use RegQueryValueEx. Michel It is a lovely language, but it takes a very long time to say anything in it, because we do not say anything in it, unless it is worth taking a very long time to say, and to listen to.
            - TreeBeard

            L 1 Reply Last reply
            0
            • L Le centriste

              Yes, that is what he meant, except for:

              LONG buffLen = MAX_PATH;
              RegQueryValue(keyHandle, "MediaPath", rgValue, &buffLen );

              Btw, you should use RegQueryValueEx. Michel It is a lovely language, but it takes a very long time to say anything in it, because we do not say anything in it, unless it is worth taking a very long time to say, and to listen to.
              - TreeBeard

              L Offline
              L Offline
              Luis E Cuadrado
              wrote on last edited by
              #6

              Hello: Well, I started to look to RegOpenKeyEx and RegQueryValueEx in MSDN. I used those in my code and it works. The help that you guys provided to me worked with these too. I want to thank you guys (Thomasz and Michel) for your help. I really appreciate it. Take care, Luis E. Cuadrado :0)

              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