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. CRegKey read from registry?

CRegKey read from registry?

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialwindows-adminquestion
10 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.
  • B Offline
    B Offline
    bosfan
    wrote on last edited by
    #1

    Hi, i need some help with CRegKey to read from registry :(. Here what works fine: int *target = NULL; AfxGetApp()->GetProfileBinary(m_strKey, _T("key"), (BYTE **)&target, &bytes); but i need to do this with registry key, like: // CRegKey is there and opened without errors int *target = NULL; myregkey.QueryBinaryValue(_T("key"), (BYTE**)&target, &bytes); Error is allways ERROR_MORE_DATA what means they are more information to read as i do? To write binary data to registry works fine to, only read is my problem now. Only for example here how i write binary to registry: int *value = new int[count]; myregkey.SetBinaryValue(_T("key"), (BYTE*)value, sizeof(int) * count); Can somebody help me how to read binary from registry with CRegKey::QueryBinaryValue?? Thanks in advance bosfan

    Richard Andrew x64R L 2 Replies Last reply
    0
    • B bosfan

      Hi, i need some help with CRegKey to read from registry :(. Here what works fine: int *target = NULL; AfxGetApp()->GetProfileBinary(m_strKey, _T("key"), (BYTE **)&target, &bytes); but i need to do this with registry key, like: // CRegKey is there and opened without errors int *target = NULL; myregkey.QueryBinaryValue(_T("key"), (BYTE**)&target, &bytes); Error is allways ERROR_MORE_DATA what means they are more information to read as i do? To write binary data to registry works fine to, only read is my problem now. Only for example here how i write binary to registry: int *value = new int[count]; myregkey.SetBinaryValue(_T("key"), (BYTE*)value, sizeof(int) * count); Can somebody help me how to read binary from registry with CRegKey::QueryBinaryValue?? Thanks in advance bosfan

      Richard Andrew x64R Offline
      Richard Andrew x64R Offline
      Richard Andrew x64
      wrote on last edited by
      #2

      ERROR_MORE_DATA usually means your buffer is not large enough. Call the function with a buffer that is large enough to receive the binary value.

      The difficult we do right away... ...the impossible takes slightly longer.

      B 1 Reply Last reply
      0
      • B bosfan

        Hi, i need some help with CRegKey to read from registry :(. Here what works fine: int *target = NULL; AfxGetApp()->GetProfileBinary(m_strKey, _T("key"), (BYTE **)&target, &bytes); but i need to do this with registry key, like: // CRegKey is there and opened without errors int *target = NULL; myregkey.QueryBinaryValue(_T("key"), (BYTE**)&target, &bytes); Error is allways ERROR_MORE_DATA what means they are more information to read as i do? To write binary data to registry works fine to, only read is my problem now. Only for example here how i write binary to registry: int *value = new int[count]; myregkey.SetBinaryValue(_T("key"), (BYTE*)value, sizeof(int) * count); Can somebody help me how to read binary from registry with CRegKey::QueryBinaryValue?? Thanks in advance bosfan

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

        As per the notes for the RegQueryValueEx function[^]

        Quote:

        If the buffer specified by lpData parameter is not large enough to hold the data, the function returns ERROR_MORE_DATA and stores the required buffer size in the variable pointed to by lpcbData. In this case, the contents of the lpData buffer are undefined.

        So set your variable bytes to zero and make the call, then when it returns it will contain the required size. You then allocate a buffer of the required size and repeat the call.

        Veni, vidi, abiit domum

        B 1 Reply Last reply
        0
        • L Lost User

          As per the notes for the RegQueryValueEx function[^]

          Quote:

          If the buffer specified by lpData parameter is not large enough to hold the data, the function returns ERROR_MORE_DATA and stores the required buffer size in the variable pointed to by lpcbData. In this case, the contents of the lpData buffer are undefined.

          So set your variable bytes to zero and make the call, then when it returns it will contain the required size. You then allocate a buffer of the required size and repeat the call.

          Veni, vidi, abiit domum

          B Offline
          B Offline
          bosfan
          wrote on last edited by
          #4

          Hi, thanks for Answer, you right, i solve it in this way! I didn know that i can check "the required size" :( Now: srg.QueryBinaryValue(_T("key"), NULL, &bytes); // then if ERROR_SUCCESS int *iArr = new int[bytes]; srg.QueryBinaryValue(_T("key"), (BYTE**)&iArr[0], &bytes); Now i now how big is the needed size, it is saved in "bytes". And i have all Data from the registry. Best regards bosfan

          L 1 Reply Last reply
          0
          • Richard Andrew x64R Richard Andrew x64

            ERROR_MORE_DATA usually means your buffer is not large enough. Call the function with a buffer that is large enough to receive the binary value.

            The difficult we do right away... ...the impossible takes slightly longer.

            B Offline
            B Offline
            bosfan
            wrote on last edited by
            #5

            Hi, thanks for answer, yes the buffer was wrong and i corrected this and now works. regards bosfan

            1 Reply Last reply
            0
            • B bosfan

              Hi, thanks for Answer, you right, i solve it in this way! I didn know that i can check "the required size" :( Now: srg.QueryBinaryValue(_T("key"), NULL, &bytes); // then if ERROR_SUCCESS int *iArr = new int[bytes]; srg.QueryBinaryValue(_T("key"), (BYTE**)&iArr[0], &bytes); Now i now how big is the needed size, it is saved in "bytes". And i have all Data from the registry. Best regards bosfan

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

              int *iArr = new int[bytes];

              Your buffer will be 4 (or even 8) times bigger than necessary; you should use:

              BYTE *iArr = new BYTE[bytes];

              Veni, vidi, abiit domum

              B 1 Reply Last reply
              0
              • L Lost User

                int *iArr = new int[bytes];

                Your buffer will be 4 (or even 8) times bigger than necessary; you should use:

                BYTE *iArr = new BYTE[bytes];

                Veni, vidi, abiit domum

                B Offline
                B Offline
                bosfan
                wrote on last edited by
                #7

                You right again, i change this, but i think if i do this in this way i can call the function without cast to byte, directly? Something like this: // regkey.QueryBinaryData(_T("key"), (BYTE**)&iArr[0], &bytes); // before regkey.QueryBinaryData(_T("key"), &iArr[0], &bytes); // now with byte array? i try this and this works to, is there any thing wrong now? bosfan

                L 1 Reply Last reply
                0
                • B bosfan

                  You right again, i change this, but i think if i do this in this way i can call the function without cast to byte, directly? Something like this: // regkey.QueryBinaryData(_T("key"), (BYTE**)&iArr[0], &bytes); // before regkey.QueryBinaryData(_T("key"), &iArr[0], &bytes); // now with byte array? i try this and this works to, is there any thing wrong now? bosfan

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

                  I cannot find a method called QueryBinaryData so I presume you are referring to CRegKey::QueryBinaryValue[^]. You could also use the simpler syntax for your buffer address thus:

                  regkey.QueryBinaryValue(_T("key"), iArr, &bytes);

                  The compiler may also still insist that you cast the buffer address to a void*.

                  Veni, vidi, abiit domum

                  B 1 Reply Last reply
                  0
                  • L Lost User

                    I cannot find a method called QueryBinaryData so I presume you are referring to CRegKey::QueryBinaryValue[^]. You could also use the simpler syntax for your buffer address thus:

                    regkey.QueryBinaryValue(_T("key"), iArr, &bytes);

                    The compiler may also still insist that you cast the buffer address to a void*.

                    Veni, vidi, abiit domum

                    B Offline
                    B Offline
                    bosfan
                    wrote on last edited by
                    #9

                    Oh no, yes of course i mean QueryBinaryValue :(, my mistake :(((. One question now, is there any difference in Unicode Version, my App is in Unicode? Regards bosfan

                    L 1 Reply Last reply
                    0
                    • B bosfan

                      Oh no, yes of course i mean QueryBinaryValue :(, my mistake :(((. One question now, is there any difference in Unicode Version, my App is in Unicode? Regards bosfan

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

                      If the data you are extracting is binary, then no, there is no difference.

                      Veni, vidi, abiit domum

                      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