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. Urgent : About SHGetValue() API used for Registry

Urgent : About SHGetValue() API used for Registry

Scheduled Pinned Locked Moved C / C++ / MFC
questionwindows-admindata-structuresjsonperformance
5 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.
  • S Offline
    S Offline
    Supriya Tonape
    wrote on last edited by
    #1

    Hi, How do I retrieve data in 5th parameter of this API. Since I dont know what will be the length of data n how will I allocate memory to this param??? Even if I declare array of maximum size it gives me error "234" i.e. "ERROR_MORE_DATA" Here is sample code... DWORD dwretrievedDataType = NULL; DWORD dwretrievedLenOfData = NULL; LPWSTR wzretrievedData = NULL; . . . // I have already given proper values for 1st 3 params dwretValue = SHGetValue(hkeyRoot, wzkeyPath, wzvalueOfKey, &dwretrievedDataType, wzretrievedData, &dwretrievedLenOfData); . . . PLz do let me know asap if anyone knows abt it... thanks n regards Supriya Tonape

    K 1 Reply Last reply
    0
    • S Supriya Tonape

      Hi, How do I retrieve data in 5th parameter of this API. Since I dont know what will be the length of data n how will I allocate memory to this param??? Even if I declare array of maximum size it gives me error "234" i.e. "ERROR_MORE_DATA" Here is sample code... DWORD dwretrievedDataType = NULL; DWORD dwretrievedLenOfData = NULL; LPWSTR wzretrievedData = NULL; . . . // I have already given proper values for 1st 3 params dwretValue = SHGetValue(hkeyRoot, wzkeyPath, wzvalueOfKey, &dwretrievedDataType, wzretrievedData, &dwretrievedLenOfData); . . . PLz do let me know asap if anyone knows abt it... thanks n regards Supriya Tonape

      K Offline
      K Offline
      kakan
      wrote on last edited by
      #2

      Heelo. The last (sixth) parameter is supposed to be the allocated length of the buffer. You must set dwretrievedLenOfData to the size of wzretrievedData before the call to SHGetValue. Now you set it to NULL. BTW, if you want to zero out a DWORD, the use 0 instead of NULL. Kakan

      S 1 Reply Last reply
      0
      • K kakan

        Heelo. The last (sixth) parameter is supposed to be the allocated length of the buffer. You must set dwretrievedLenOfData to the size of wzretrievedData before the call to SHGetValue. Now you set it to NULL. BTW, if you want to zero out a DWORD, the use 0 instead of NULL. Kakan

        S Offline
        S Offline
        Supriya Tonape
        wrote on last edited by
        #3

        Hi Kakan, I dont want to hard code any value, like size of 5th param... b4 giving this param as input to 'SHGetValue()' U need to allocate memory for 'dwretrievedData'..I did read abt the documentation of it in MSDN Thanks in ton for help coz I am done with my problem :) bye Supriya Tonape

        K 1 Reply Last reply
        0
        • S Supriya Tonape

          Hi Kakan, I dont want to hard code any value, like size of 5th param... b4 giving this param as input to 'SHGetValue()' U need to allocate memory for 'dwretrievedData'..I did read abt the documentation of it in MSDN Thanks in ton for help coz I am done with my problem :) bye Supriya Tonape

          K Offline
          K Offline
          kakan
          wrote on last edited by
          #4

          Hello again. I'm pleased to be able to help you out. About the buffer size, at some time or another you will have to allocate the buffer for the return value, hardcoded or not... In general, the Windows functions that return buffers usually has a way to give the coder the size of buffer needed for a particular reply.: 1. Set the buffer pointer to NULL, and allocated buffer size to 0. 2. Call the function in question. 3. The function returns the number of bytes/chars needed for the (real) response. 4. Allocate that amount of memory för the buffer. 5. Call the function again, this time with a valid buffer address and the number of allocated bytes. 6. Obtain the result. But I'm not sure if this goes for SHGetValue, though. I haven't checked. But this principle goes for many Windows functions. Kakan.

          S 1 Reply Last reply
          0
          • K kakan

            Hello again. I'm pleased to be able to help you out. About the buffer size, at some time or another you will have to allocate the buffer for the return value, hardcoded or not... In general, the Windows functions that return buffers usually has a way to give the coder the size of buffer needed for a particular reply.: 1. Set the buffer pointer to NULL, and allocated buffer size to 0. 2. Call the function in question. 3. The function returns the number of bytes/chars needed for the (real) response. 4. Allocate that amount of memory för the buffer. 5. Call the function again, this time with a valid buffer address and the number of allocated bytes. 6. Obtain the result. But I'm not sure if this goes for SHGetValue, though. I haven't checked. But this principle goes for many Windows functions. Kakan.

            S Offline
            S Offline
            Supriya Tonape
            wrote on last edited by
            #5

            Hi, No It doesnt work for it. Though it doesnt give any error but buffer size returned is the size of DWORD. Bye Supriya Tonape

            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