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 write registry?

How to write registry?

Scheduled Pinned Locked Moved C / C++ / MFC
windows-admintutorialquestion
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.
  • T Offline
    T Offline
    Thomas Lau
    wrote on last edited by
    #1

    I am building a project.I want to write something to registry to save some informatiom.

    T 1 Reply Last reply
    0
    • T Thomas Lau

      I am building a project.I want to write something to registry to save some informatiom.

      T Offline
      T Offline
      Thomas Lau
      wrote on last edited by
      #2

      Who can give me a sample or a demo?

      P C 2 Replies Last reply
      0
      • T Thomas Lau

        Who can give me a sample or a demo?

        P Offline
        P Offline
        parths
        wrote on last edited by
        #3

        Use RegOpenKey, RegQueryValue, RegCloseKey. You can look for sample code in MSDN, or you can search Google for a whole lot of sample code You might also find some code on CP "It was when I found out I could make mistakes that I knew I was on to something." -Ornette Coleman

        1 Reply Last reply
        0
        • T Thomas Lau

          Who can give me a sample or a demo?

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

          Here are some code snippets, which you may use : ////////////////////////////////////////////////////// CString GetFromRegistry( CString csRegKeyString, CString csRegKeyField, CString csDefault ) { CString csResult = csDefault; CRegKey* pRK = new CRegKey(); LONG lRegOpen = pRK->Open(HKEY_LOCAL_MACHINE, csRegKeyString); if(lRegOpen == ERROR_SUCCESS) { char cValue[1000]; memset( cValue, 0, sizeof( cValue ) ); DWORD dwSize = sizeof( cValue ); LONG lRegQuery = pRK->QueryValue( &(cValue[0]), csRegKeyField, &dwSize ); if(lRegQuery == ERROR_SUCCESS) csResult = cValue; } delete pRK; pRK = NULL; return( csResult ); } ////////////////////////////////////////////////////// BOOL SetInRegistry( CString csRegKeyString, CString csRegKeyField, CString csValue ) { BOOL bResult = FALSE; CRegKey* pRK = new CRegKey(); LONG lRegSetValue = pRK->SetValue( HKEY_LOCAL_MACHINE, csRegKeyString, csValue, csRegKeyField ); if(lRegSetValue == ERROR_SUCCESS) bResult = TRUE; delete pRK; pRK = NULL; return( bResult ); } I think there are a lot of complete classes here at codeguru. Use the code above only as an example how you may do it. Best regards

          T D 2 Replies Last reply
          0
          • C csc

            Here are some code snippets, which you may use : ////////////////////////////////////////////////////// CString GetFromRegistry( CString csRegKeyString, CString csRegKeyField, CString csDefault ) { CString csResult = csDefault; CRegKey* pRK = new CRegKey(); LONG lRegOpen = pRK->Open(HKEY_LOCAL_MACHINE, csRegKeyString); if(lRegOpen == ERROR_SUCCESS) { char cValue[1000]; memset( cValue, 0, sizeof( cValue ) ); DWORD dwSize = sizeof( cValue ); LONG lRegQuery = pRK->QueryValue( &(cValue[0]), csRegKeyField, &dwSize ); if(lRegQuery == ERROR_SUCCESS) csResult = cValue; } delete pRK; pRK = NULL; return( csResult ); } ////////////////////////////////////////////////////// BOOL SetInRegistry( CString csRegKeyString, CString csRegKeyField, CString csValue ) { BOOL bResult = FALSE; CRegKey* pRK = new CRegKey(); LONG lRegSetValue = pRK->SetValue( HKEY_LOCAL_MACHINE, csRegKeyString, csValue, csRegKeyField ); if(lRegSetValue == ERROR_SUCCESS) bResult = TRUE; delete pRK; pRK = NULL; return( bResult ); } I think there are a lot of complete classes here at codeguru. Use the code above only as an example how you may do it. Best regards

            T Offline
            T Offline
            Thomas Lau
            wrote on last edited by
            #5

            Thank you very much!!

            1 Reply Last reply
            0
            • C csc

              Here are some code snippets, which you may use : ////////////////////////////////////////////////////// CString GetFromRegistry( CString csRegKeyString, CString csRegKeyField, CString csDefault ) { CString csResult = csDefault; CRegKey* pRK = new CRegKey(); LONG lRegOpen = pRK->Open(HKEY_LOCAL_MACHINE, csRegKeyString); if(lRegOpen == ERROR_SUCCESS) { char cValue[1000]; memset( cValue, 0, sizeof( cValue ) ); DWORD dwSize = sizeof( cValue ); LONG lRegQuery = pRK->QueryValue( &(cValue[0]), csRegKeyField, &dwSize ); if(lRegQuery == ERROR_SUCCESS) csResult = cValue; } delete pRK; pRK = NULL; return( csResult ); } ////////////////////////////////////////////////////// BOOL SetInRegistry( CString csRegKeyString, CString csRegKeyField, CString csValue ) { BOOL bResult = FALSE; CRegKey* pRK = new CRegKey(); LONG lRegSetValue = pRK->SetValue( HKEY_LOCAL_MACHINE, csRegKeyString, csValue, csRegKeyField ); if(lRegSetValue == ERROR_SUCCESS) bResult = TRUE; delete pRK; pRK = NULL; return( bResult ); } I think there are a lot of complete classes here at codeguru. Use the code above only as an example how you may do it. Best regards

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

              csc wrote: I think there are a lot of complete classes here at codeguru. Codeguru? Don't you mean CodeProject? :)

              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