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. Reading Windows Registry data in 64 bit operating system

Reading Windows Registry data in 64 bit operating system

Scheduled Pinned Locked Moved C / C++ / MFC
databasewindows-adminjsonhelp
13 Posts 6 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.
  • M Offline
    M Offline
    msr_codeproject
    wrote on last edited by
    #1

    Hi friends, here is my query... I am working on win32. I am writing an application to read some data from registry. It is working on 32 bit machines. But it is not working on 64 bit machines. I am using the below API to read the data. RegQueryValueEx(hKey, pszEntry, NULL, NULL, (LPBYTE)pData, 200) Is there any problem with the last parameter size (200). What size to be passed as parameter. Thanks in advance. Regards Sairam M.

    L E 2 Replies Last reply
    0
    • M msr_codeproject

      Hi friends, here is my query... I am working on win32. I am writing an application to read some data from registry. It is working on 32 bit machines. But it is not working on 64 bit machines. I am using the below API to read the data. RegQueryValueEx(hKey, pszEntry, NULL, NULL, (LPBYTE)pData, 200) Is there any problem with the last parameter size (200). What size to be passed as parameter. Thanks in advance. Regards Sairam M.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      msr_codeproject wrote:

      Is there any problem with the last parameter size (200). What size to be passed as parameter.

      This parameter should be the address of (pointer to) a variable that contains the length of the buffer, as described here[^]. If this size is not large enough for the result then the call will fail and the required size will be entered into the variable. Thus if you make a call with the variable set to zero you can find out how big the buffer needs to be and allocate as appropriate. BTW I'm not sure why your question got downvoted so I have upped it to compensate.

      It's time for a new signature.

      M M 2 Replies Last reply
      0
      • L Lost User

        msr_codeproject wrote:

        Is there any problem with the last parameter size (200). What size to be passed as parameter.

        This parameter should be the address of (pointer to) a variable that contains the length of the buffer, as described here[^]. If this size is not large enough for the result then the call will fail and the required size will be entered into the variable. Thus if you make a call with the variable set to zero you can find out how big the buffer needs to be and allocate as appropriate. BTW I'm not sure why your question got downvoted so I have upped it to compensate.

        It's time for a new signature.

        M Offline
        M Offline
        Mattias G
        wrote on last edited by
        #3

        The strange thing is that your code actually worked in the 32 bit edition. Any call to RegQueryValueEx using your parameters would result in an attempt to write something at memory address 200. Not good.

        L 1 Reply Last reply
        0
        • M Mattias G

          The strange thing is that your code actually worked in the 32 bit edition. Any call to RegQueryValueEx using your parameters would result in an attempt to write something at memory address 200. Not good.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Mattias G wrote:

          The strange thing is that your code actually worked

          Firstly, that was the OP's code, not mine. Secondly, I don't think it did work correctly.

          It's time for a new signature.

          M 1 Reply Last reply
          0
          • L Lost User

            Mattias G wrote:

            The strange thing is that your code actually worked

            Firstly, that was the OP's code, not mine. Secondly, I don't think it did work correctly.

            It's time for a new signature.

            M Offline
            M Offline
            Mattias G
            wrote on last edited by
            #5

            Right, "your" was referring to the OP, naturally. Could have been more clear on that :)

            L 1 Reply Last reply
            0
            • M Mattias G

              Right, "your" was referring to the OP, naturally. Could have been more clear on that :)

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              What I meant was you should have posted your reply to the OP, not to me.

              It's time for a new signature.

              1 Reply Last reply
              0
              • L Lost User

                msr_codeproject wrote:

                Is there any problem with the last parameter size (200). What size to be passed as parameter.

                This parameter should be the address of (pointer to) a variable that contains the length of the buffer, as described here[^]. If this size is not large enough for the result then the call will fail and the required size will be entered into the variable. Thus if you make a call with the variable set to zero you can find out how big the buffer needs to be and allocate as appropriate. BTW I'm not sure why your question got downvoted so I have upped it to compensate.

                It's time for a new signature.

                M Offline
                M Offline
                msr_codeproject
                wrote on last edited by
                #7

                Hi Guys, my trails are not working. I am giving you the path of the key. Please write small code to read it. Key Path: HKEY_CURRENT_USER\Software\ABCD\ABCD UD PCL6_00-00-00-00-00-00\printer_ui\icc_profile\0 Name of the filed: szResId Type of the field: REG_DWORD Data at the field: 0x000084d6(34006) Now I want to read 0x000084d6. I tried in so many ways. But it wasn't worked. Help me. Regards msr_codeproject

                D L 2 Replies Last reply
                0
                • M msr_codeproject

                  Hi Guys, my trails are not working. I am giving you the path of the key. Please write small code to read it. Key Path: HKEY_CURRENT_USER\Software\ABCD\ABCD UD PCL6_00-00-00-00-00-00\printer_ui\icc_profile\0 Name of the filed: szResId Type of the field: REG_DWORD Data at the field: 0x000084d6(34006) Now I want to read 0x000084d6. I tried in so many ways. But it wasn't worked. Help me. Regards msr_codeproject

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

                  msr_codeproject wrote:

                  I tried in so many ways. But it wasn't worked. Help me.

                  Show the code you've tried so far.

                  "One man's wage rise is another man's price increase." - Harold Wilson

                  "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                  "Man who follows car will be exhausted." - Confucius

                  1 Reply Last reply
                  0
                  • M msr_codeproject

                    Hi friends, here is my query... I am working on win32. I am writing an application to read some data from registry. It is working on 32 bit machines. But it is not working on 64 bit machines. I am using the below API to read the data. RegQueryValueEx(hKey, pszEntry, NULL, NULL, (LPBYTE)pData, 200) Is there any problem with the last parameter size (200). What size to be passed as parameter. Thanks in advance. Regards Sairam M.

                    E Offline
                    E Offline
                    Electron Shepherd
                    wrote on last edited by
                    #9

                    The last parameter is wrong. It needs to be a pointer to a DWORD that gives the size of the buffer, not the size of the buffer itself. Currently, your code is using the value of the memory at address 200 as the buffer size, and that could be anything... Try:

                    DWORD cbSize = 200;

                    RegQueryValueEx(hKey, pszEntry, NULL, NULL, (LPBYTE)pData, &cbSize);

                    Server and Network Monitoring

                    1 Reply Last reply
                    0
                    • M msr_codeproject

                      Hi Guys, my trails are not working. I am giving you the path of the key. Please write small code to read it. Key Path: HKEY_CURRENT_USER\Software\ABCD\ABCD UD PCL6_00-00-00-00-00-00\printer_ui\icc_profile\0 Name of the filed: szResId Type of the field: REG_DWORD Data at the field: 0x000084d6(34006) Now I want to read 0x000084d6. I tried in so many ways. But it wasn't worked. Help me. Regards msr_codeproject

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #10

                      Try the following:

                      static PWSTR pszKeyName = L"Software\\ABCD\\ABCD UD PCL6_00-00-00-00-00-00\\printer_ui\\icc_profile";

                      LONG lResult;
                      HKEY hkMyKey;
                      DWORD dwDisposition;
                      DWORD dwType;
                      DWORD dwData;
                      DWORD dwSize;

                      lResult = RegCreateKeyEx(HKEY_CURRENT_USER,
                      pszKeyName,
                      0,
                      NULL,
                      0,
                      KEY_READ,
                      NULL,
                      &hkMyKey,
                      &dwDisposition
                      );
                      if (ERROR_SUCCESS == lResult)
                      {
                      dwSize = sizeof dwData;
                      lResult = RegGetValue(hkMyKey,
                      L"0",
                      L"szResId",
                      RRF_RT_ANY,
                      &dwType,
                      &dwData,
                      &dwSize
                      );
                      }

                      Note: this is a Win32 solution, I don't have access to a 64-bit system.

                      It's time for a new signature.

                      M 1 Reply Last reply
                      0
                      • L Lost User

                        Try the following:

                        static PWSTR pszKeyName = L"Software\\ABCD\\ABCD UD PCL6_00-00-00-00-00-00\\printer_ui\\icc_profile";

                        LONG lResult;
                        HKEY hkMyKey;
                        DWORD dwDisposition;
                        DWORD dwType;
                        DWORD dwData;
                        DWORD dwSize;

                        lResult = RegCreateKeyEx(HKEY_CURRENT_USER,
                        pszKeyName,
                        0,
                        NULL,
                        0,
                        KEY_READ,
                        NULL,
                        &hkMyKey,
                        &dwDisposition
                        );
                        if (ERROR_SUCCESS == lResult)
                        {
                        dwSize = sizeof dwData;
                        lResult = RegGetValue(hkMyKey,
                        L"0",
                        L"szResId",
                        RRF_RT_ANY,
                        &dwType,
                        &dwData,
                        &dwSize
                        );
                        }

                        Note: this is a Win32 solution, I don't have access to a 64-bit system.

                        It's time for a new signature.

                        M Offline
                        M Offline
                        MicroVirus
                        wrote on last edited by
                        #11

                        Richard MacCutchan wrote:

                        static PWSTR pszKeyName = L"Software\\ABCD\\ABCD UD PCL6_00-00-00-00-00-00\\printer_ui\\icc_profile";

                        I think you should make pszKeyName constant (i.e. static LPCWSTR), considering you're referencing it to memory (the string literal) that could be read-only.

                        L 1 Reply Last reply
                        0
                        • M MicroVirus

                          Richard MacCutchan wrote:

                          static PWSTR pszKeyName = L"Software\\ABCD\\ABCD UD PCL6_00-00-00-00-00-00\\printer_ui\\icc_profile";

                          I think you should make pszKeyName constant (i.e. static LPCWSTR), considering you're referencing it to memory (the string literal) that could be read-only.

                          L Offline
                          L Offline
                          Lost User
                          wrote on last edited by
                          #12

                          MicroVirus wrote:

                          I think you should make pszKeyName constant (i.e. static LPCWSTR), considering you're referencing it to memory (the string literal) that could be read-only.

                          This is a simple example of how to get a value from a registry key; making the keyname const will have no effect on the code I provided.

                          It's time for a new signature.

                          M 1 Reply Last reply
                          0
                          • L Lost User

                            MicroVirus wrote:

                            I think you should make pszKeyName constant (i.e. static LPCWSTR), considering you're referencing it to memory (the string literal) that could be read-only.

                            This is a simple example of how to get a value from a registry key; making the keyname const will have no effect on the code I provided.

                            It's time for a new signature.

                            M Offline
                            M Offline
                            MicroVirus
                            wrote on last edited by
                            #13

                            Richard MacCutchan wrote:

                            This is a simple example of how to get a value from a registry key; making the keyname const will have no effect on the code I provided.

                            True, but it's still good to realise that it should be const. If someone reads your post and decides to adapt it, having it to const to begin with could be useful. I know, I'm whining... :sigh: It's just that I feel it's an overlooked detail; I forget it myself, so that's why I find it important

                            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