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. Registry

Registry

Scheduled Pinned Locked Moved C / C++ / MFC
windows-adminhelpquestion
6 Posts 4 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.
  • C Offline
    C Offline
    capint
    wrote on last edited by
    #1

    I use this code to create a value in Registry: CString strValue; DWORD dwBytes ; LPBYTE lpData ; strValue=_T("1doandaithietladaidaihoncaidoanhoinaylunnecoithumaychaydcko?"); dwBytes = strValue.GetLength()+1; lpData = (LPBYTE) strValue.GetBuffer(dwBytes); ::RegSetValueEx(m_hSectionKey, _T("Test"), NULL, REG_SZ, lpData, dwBytes); But the value data in Registry is just : "1doandaithietladaidaihoncaidoa" Someone plz help me to explain & give me a solution :sigh:

    C H C D 4 Replies Last reply
    0
    • C capint

      I use this code to create a value in Registry: CString strValue; DWORD dwBytes ; LPBYTE lpData ; strValue=_T("1doandaithietladaidaihoncaidoanhoinaylunnecoithumaychaydcko?"); dwBytes = strValue.GetLength()+1; lpData = (LPBYTE) strValue.GetBuffer(dwBytes); ::RegSetValueEx(m_hSectionKey, _T("Test"), NULL, REG_SZ, lpData, dwBytes); But the value data in Registry is just : "1doandaithietladaidaihoncaidoa" Someone plz help me to explain & give me a solution :sigh:

      C Offline
      C Offline
      CPallini
      wrote on last edited by
      #2

      Your building a UNICODE application hence each character is 2 bytes wide. The correct value for dwBytes is:

      dwBytes = (strValue.getLength()+1)*sizeof(TCHAR);

      :)

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

      1 Reply Last reply
      0
      • C capint

        I use this code to create a value in Registry: CString strValue; DWORD dwBytes ; LPBYTE lpData ; strValue=_T("1doandaithietladaidaihoncaidoanhoinaylunnecoithumaychaydcko?"); dwBytes = strValue.GetLength()+1; lpData = (LPBYTE) strValue.GetBuffer(dwBytes); ::RegSetValueEx(m_hSectionKey, _T("Test"), NULL, REG_SZ, lpData, dwBytes); But the value data in Registry is just : "1doandaithietladaidaihoncaidoa" Someone plz help me to explain & give me a solution :sigh:

        H Offline
        H Offline
        Hamid Taebi
        wrote on last edited by
        #3

        And see this[^] article for more help.

        1 Reply Last reply
        0
        • C capint

          I use this code to create a value in Registry: CString strValue; DWORD dwBytes ; LPBYTE lpData ; strValue=_T("1doandaithietladaidaihoncaidoanhoinaylunnecoithumaychaydcko?"); dwBytes = strValue.GetLength()+1; lpData = (LPBYTE) strValue.GetBuffer(dwBytes); ::RegSetValueEx(m_hSectionKey, _T("Test"), NULL, REG_SZ, lpData, dwBytes); But the value data in Registry is just : "1doandaithietladaidaihoncaidoa" Someone plz help me to explain & give me a solution :sigh:

          C Offline
          C Offline
          capint
          wrote on last edited by
          #4

          Oh It worked, thanks so much :D

          1 Reply Last reply
          0
          • C capint

            I use this code to create a value in Registry: CString strValue; DWORD dwBytes ; LPBYTE lpData ; strValue=_T("1doandaithietladaidaihoncaidoanhoinaylunnecoithumaychaydcko?"); dwBytes = strValue.GetLength()+1; lpData = (LPBYTE) strValue.GetBuffer(dwBytes); ::RegSetValueEx(m_hSectionKey, _T("Test"), NULL, REG_SZ, lpData, dwBytes); But the value data in Registry is just : "1doandaithietladaidaihoncaidoa" Someone plz help me to explain & give me a solution :sigh:

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

            Why are you calling GetBuffer()? Unless you are also modifying strValue, it is unnecessary and potentially dangerous.

            "Love people and use things, not love things and use people." - Unknown

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

            C 1 Reply Last reply
            0
            • D David Crow

              Why are you calling GetBuffer()? Unless you are also modifying strValue, it is unnecessary and potentially dangerous.

              "Love people and use things, not love things and use people." - Unknown

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

              C Offline
              C Offline
              CPallini
              wrote on last edited by
              #6

              Good point. :)

              If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
              This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

              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