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 REG_BINARY Problem

Registry REG_BINARY Problem

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++databasevisual-studiowindows-admin
11 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 locoone

    im trying to get RecentDocs registry info and put it in a listctrl the name part works fine but the data part i only get the first letter

    #define MAX_KEY_LENGTH 255
    #define MAX_VALUE_NAME 16383
    TCHAR achValue[MAX_VALUE_NAME];
    DWORD cchValue = MAX_VALUE_NAME;
    HKEY hKey;
    dwData = MAX_VALUE_NAME;
    cchValue = MAX_VALUE_NAME;
    achValue[0] = '\0';
    retCode = RegEnumValue(hKey, i,
    achValue,
    &cchValue,
    NULL,
    &dwType,
    (BYTE*)lpData,
    (LPDWORD)&dwData);

    if (retCode == ERROR\_SUCCESS ) 
    { 
    	m\_list.InsertItem(index, achValue);
    	m\_list.SetItemText(index, 1, lpData);
    	index++;
    }
    

    im using vs 2008 and mfc can anyone tell me where im going wrong? :confused:

    B Offline
    B Offline
    Baltoro
    wrote on last edited by
    #2

    Your attempting to pass a binary string to a function that expects a TCHAR string. You should convert it to some meaningful character string format first. The function will interpret the each byte of the binary value as char (char is a byte).

    L 1 Reply Last reply
    0
    • B Baltoro

      Your attempting to pass a binary string to a function that expects a TCHAR string. You should convert it to some meaningful character string format first. The function will interpret the each byte of the binary value as char (char is a byte).

      L Offline
      L Offline
      locoone
      wrote on last edited by
      #3

      i forgot to add these

      TCHAR lpData[MAX_VALUE_NAME];
      DWORD dwType = REG_BINARY;
      DWORD dwData = MAX_VALUE_NAME;

      but it is a TCHAR so im still lost as to what to do to fix it :(

      C 1 Reply Last reply
      0
      • L locoone

        i forgot to add these

        TCHAR lpData[MAX_VALUE_NAME];
        DWORD dwType = REG_BINARY;
        DWORD dwData = MAX_VALUE_NAME;

        but it is a TCHAR so im still lost as to what to do to fix it :(

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

        Is yours a ANSI build (i.e. not UNICODE)?

        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
        [My articles]

        L 1 Reply Last reply
        0
        • C CPallini

          Is yours a ANSI build (i.e. not UNICODE)?

          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
          [My articles]

          L Offline
          L Offline
          locoone
          wrote on last edited by
          #5

          yes, its not unicode.

          C 1 Reply Last reply
          0
          • L locoone

            yes, its not unicode.

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

            Change:

            locoone wrote:

            if (retCode == ERROR_SUCCESS ) { m_list.InsertItem(index, achValue); m_list.SetItemText(index, 1, lpData); index++; }

            to

            if (retCode == ERROR_SUCCESS )
            {
            CString str = (wchar_t *) lpData;
            m_list.InsertItem(index, achValue);
            m_list.SetItemText(index, 1, str);
            index++;
            }

            :)

            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
            [My articles]

            L 1 Reply Last reply
            0
            • C CPallini

              Change:

              locoone wrote:

              if (retCode == ERROR_SUCCESS ) { m_list.InsertItem(index, achValue); m_list.SetItemText(index, 1, lpData); index++; }

              to

              if (retCode == ERROR_SUCCESS )
              {
              CString str = (wchar_t *) lpData;
              m_list.InsertItem(index, achValue);
              m_list.SetItemText(index, 1, str);
              index++;
              }

              :)

              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
              [My articles]

              L Offline
              L Offline
              locoone
              wrote on last edited by
              #7

              i changed it and i now get this error error C2440: 'initializing' : cannot convert from 'wchar_t *' to 'ATL::CStringT<BaseType,StringTraits>'

              C 1 Reply Last reply
              0
              • L locoone

                i changed it and i now get this error error C2440: 'initializing' : cannot convert from 'wchar_t *' to 'ATL::CStringT<BaseType,StringTraits>'

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

                Try (I haven't ATL here so I may only guess)

                if (retCode == ERROR_SUCCESS )
                {
                m_list.InsertItem(index, achValue);
                m_list.SetItemText(index, 1, CW2A(lpData));
                index++;
                }

                :)

                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
                [My articles]

                L 1 Reply Last reply
                0
                • C CPallini

                  Try (I haven't ATL here so I may only guess)

                  if (retCode == ERROR_SUCCESS )
                  {
                  m_list.InsertItem(index, achValue);
                  m_list.SetItemText(index, 1, CW2A(lpData));
                  index++;
                  }

                  :)

                  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
                  [My articles]

                  L Offline
                  L Offline
                  locoone
                  wrote on last edited by
                  #9

                  that gives the same error :(( but why am i only getting the first letter and not the whole value? :confused: HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\RecentDocs <--- thats what im tring to get

                  modified on Sunday, April 12, 2009 11:07 PM

                  C 1 Reply Last reply
                  0
                  • L locoone

                    that gives the same error :(( but why am i only getting the first letter and not the whole value? :confused: HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\RecentDocs <--- thats what im tring to get

                    modified on Sunday, April 12, 2009 11:07 PM

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

                    locoone wrote:

                    that gives the same error

                    It shouldn't.

                    locoone wrote:

                    but why am i only getting the first letter and not the whole value?

                    Because lpData contains a UNICODE string, while you need a ANSI one. Since seems you've troubles with ATL conversion macros, try using the oldie-goldie WideCharToMultyByte [^] function. For instance (beware: quick and dirty fix):

                    if (retCode == ERROR_SUCCESS )
                    {
                    // supposing UNICODE NOT DEFINED
                    char buffer[200];
                    WideCharToMultiByte(CP_ACP, 0, lpData, -1, buffer, 200, NULL, NULL);
                    m_list.InsertItem(index, achValue);
                    m_list.SetItemText(index, 1, buffer);
                    index++;
                    }

                    :)

                    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
                    [My articles]

                    L 1 Reply Last reply
                    0
                    • C CPallini

                      locoone wrote:

                      that gives the same error

                      It shouldn't.

                      locoone wrote:

                      but why am i only getting the first letter and not the whole value?

                      Because lpData contains a UNICODE string, while you need a ANSI one. Since seems you've troubles with ATL conversion macros, try using the oldie-goldie WideCharToMultyByte [^] function. For instance (beware: quick and dirty fix):

                      if (retCode == ERROR_SUCCESS )
                      {
                      // supposing UNICODE NOT DEFINED
                      char buffer[200];
                      WideCharToMultiByte(CP_ACP, 0, lpData, -1, buffer, 200, NULL, NULL);
                      m_list.InsertItem(index, achValue);
                      m_list.SetItemText(index, 1, buffer);
                      index++;
                      }

                      :)

                      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
                      [My articles]

                      L Offline
                      L Offline
                      locoone
                      wrote on last edited by
                      #11

                      that worked thanks man :-D

                      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