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. how to read a DWORD value from registry

how to read a DWORD value from registry

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

    Can someone please tell me how I can read a DWORD value from the registry and display it as a decimal. I registry API function that I have looked at seem only to be able to read a string value. Help with this is most appreciated. - SAK

    J A 2 Replies Last reply
    0
    • S SAK

      Can someone please tell me how I can read a DWORD value from the registry and display it as a decimal. I registry API function that I have looked at seem only to be able to read a string value. Help with this is most appreciated. - SAK

      J Offline
      J Offline
      Jason Henderson
      wrote on last edited by
      #2

      There are countless registry articles on CP, but here is a function I use:

      DWORD CGlobalUtility::GetRegDWORD(HKEY hKey, CString cstrSubKey, CString cstrVar)
      {
      DWORD dwRetVal = 0;
      DWORD dwTemp, dwSize = sizeof(DWORD);
      HKEY phkResult;

      if (RegOpenKeyEx(hKey, cstrSubKey, 0, KEY\_QUERY\_VALUE, &phkResult) == ERROR\_SUCCESS)
      {
      	RegQueryValueEx(phkResult, cstrVar, NULL, &dwTemp, (LPBYTE)&dwRetVal, &dwSize);
      
      	RegCloseKey(phkResult);
      }
      
      return dwRetVal;
      

      };

      Jason Henderson
      start page ; articles henderson is coming henderson is an opponent's worst nightmare * googlism *

      J 1 Reply Last reply
      0
      • J Jason Henderson

        There are countless registry articles on CP, but here is a function I use:

        DWORD CGlobalUtility::GetRegDWORD(HKEY hKey, CString cstrSubKey, CString cstrVar)
        {
        DWORD dwRetVal = 0;
        DWORD dwTemp, dwSize = sizeof(DWORD);
        HKEY phkResult;

        if (RegOpenKeyEx(hKey, cstrSubKey, 0, KEY\_QUERY\_VALUE, &phkResult) == ERROR\_SUCCESS)
        {
        	RegQueryValueEx(phkResult, cstrVar, NULL, &dwTemp, (LPBYTE)&dwRetVal, &dwSize);
        
        	RegCloseKey(phkResult);
        }
        
        return dwRetVal;
        

        };

        Jason Henderson
        start page ; articles henderson is coming henderson is an opponent's worst nightmare * googlism *

        J Offline
        J Offline
        Jason Henderson
        wrote on last edited by
        #3

        oops. take out that CGlobalUtility stuff.

        Jason Henderson
        start page ; articles henderson is coming henderson is an opponent's worst nightmare * googlism *

        1 Reply Last reply
        0
        • S SAK

          Can someone please tell me how I can read a DWORD value from the registry and display it as a decimal. I registry API function that I have looked at seem only to be able to read a string value. Help with this is most appreciated. - SAK

          A Offline
          A Offline
          Alvaro Mendez
          wrote on last edited by
          #4

          For your case reading the value as a string is the best thing. Then all you need is to convert it to a double using atof or _tcstod (for UNICODE). Regards, Alvaro


          Well done is better than well said. -- Benjamin Franklin (I actually prefer medium-well.)

          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