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. Readinf From The Registry [modified]

Readinf From The Registry [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
questionwindows-adminhelp
4 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
    Semion_N
    wrote on last edited by
    #1

    Hello, I'm trying to read from the registry a value from a key, but I don't understand some parameters from the reading function. here is a piece of code: CRegKey key; key.Open(HKEY_LOCAL_MACHINE,"Software\\MyProject\\key"); key.SetStringValue("TRUE","TRUE"); if (key.QueryStringValue(**?**,**?**,**?**)=="TRUE") MessageBox("TRUE"); I dont understand the parameters within the QueryStringValue( ) Can you please explain for me what this parameters do and what values for instance I can set to the parameters? Another problem: Every time I execute the program I'm getting an assertation that m_hKey ! = 0 I tried to remove the ASSERT line: **ATLASSERT(m_hKey != NULL);** but it still stops at the line of this assert and gives me the assertation although I removed it. why? and how can I remove it for real? Thanking you in advance! -- modified at 15:45 Thursday 27th July, 2006

    P 1 Reply Last reply
    0
    • S Semion_N

      Hello, I'm trying to read from the registry a value from a key, but I don't understand some parameters from the reading function. here is a piece of code: CRegKey key; key.Open(HKEY_LOCAL_MACHINE,"Software\\MyProject\\key"); key.SetStringValue("TRUE","TRUE"); if (key.QueryStringValue(**?**,**?**,**?**)=="TRUE") MessageBox("TRUE"); I dont understand the parameters within the QueryStringValue( ) Can you please explain for me what this parameters do and what values for instance I can set to the parameters? Another problem: Every time I execute the program I'm getting an assertation that m_hKey ! = 0 I tried to remove the ASSERT line: **ATLASSERT(m_hKey != NULL);** but it still stops at the line of this assert and gives me the assertation although I removed it. why? and how can I remove it for real? Thanking you in advance! -- modified at 15:45 Thursday 27th July, 2006

      P Offline
      P Offline
      PJ Arends
      wrote on last edited by
      #2

      Semion_N wrote:

      CRegKey key; key.Open(HKEY_LOCAL_MACHINE,"Software\\MyProject\\key");

      What is the return value? Open will fail if HKLM\Software\MyProject\key does not exist. Use CRegKey::Create() instead.

      Semion_N wrote:

      Every time I execute the program I'm getting an assertation that m_hKey ! = 0

      key.open() is failing, so CRegKey::m_hKey is zero. Do not remove the ASSERTS, they are used to tell you when you do something wrong.

      Semion_N wrote:

      key.QueryStringValue(?,?,?)

      From MSDN: Parameters pszValueName Pointer to a null-terminated string containing the name of the value to query. pszValue Pointer to a buffer that receives the string data. pnChars The size, in TCHARs, of the buffer pointed to by pszValue. When the method returns, pnChars contains the size, in TCHARs, of the string retrieved, including a terminating null character. Return Value If the method succeeds, ERROR_SUCCESS is returned. If the method fails to read a value, it returns a nonzero error code defined in WINERROR.H. If the data referenced is not of type REG_SZ, ERROR_INVALID_DATA is returned. If the method returns ERROR_MORE_DATA, pnChars equals zero, not the required buffer size in bytes.

      CRegKey key;
      if (ERROR_SUCCESS == key.Create(HKEY_LOCAL_MACHINE, "Software\\MyProject\\key"))
      {
      if (ERROR_SUCCESS == key.SetStringValue("TRUE_KEY", "TRUE_VALUE"))
      {
      char readbuffer[30] = {0};
      ULONG buffersize = 30;
      if (ERROR_SUCCESS == key.QueryStringValue("TRUE_KEY", readbuffer, &buffersize))
      {
      if (0 == strcmp(readbuffer, "TRUE_VALUE"))
      {
      MessageBox("TRUE");
      }
      }
      }
      }

      S 1 Reply Last reply
      0
      • P PJ Arends

        Semion_N wrote:

        CRegKey key; key.Open(HKEY_LOCAL_MACHINE,"Software\\MyProject\\key");

        What is the return value? Open will fail if HKLM\Software\MyProject\key does not exist. Use CRegKey::Create() instead.

        Semion_N wrote:

        Every time I execute the program I'm getting an assertation that m_hKey ! = 0

        key.open() is failing, so CRegKey::m_hKey is zero. Do not remove the ASSERTS, they are used to tell you when you do something wrong.

        Semion_N wrote:

        key.QueryStringValue(?,?,?)

        From MSDN: Parameters pszValueName Pointer to a null-terminated string containing the name of the value to query. pszValue Pointer to a buffer that receives the string data. pnChars The size, in TCHARs, of the buffer pointed to by pszValue. When the method returns, pnChars contains the size, in TCHARs, of the string retrieved, including a terminating null character. Return Value If the method succeeds, ERROR_SUCCESS is returned. If the method fails to read a value, it returns a nonzero error code defined in WINERROR.H. If the data referenced is not of type REG_SZ, ERROR_INVALID_DATA is returned. If the method returns ERROR_MORE_DATA, pnChars equals zero, not the required buffer size in bytes.

        CRegKey key;
        if (ERROR_SUCCESS == key.Create(HKEY_LOCAL_MACHINE, "Software\\MyProject\\key"))
        {
        if (ERROR_SUCCESS == key.SetStringValue("TRUE_KEY", "TRUE_VALUE"))
        {
        char readbuffer[30] = {0};
        ULONG buffersize = 30;
        if (ERROR_SUCCESS == key.QueryStringValue("TRUE_KEY", readbuffer, &buffersize))
        {
        if (0 == strcmp(readbuffer, "TRUE_VALUE"))
        {
        MessageBox("TRUE");
        }
        }
        }
        }

        S Offline
        S Offline
        Semion_N
        wrote on last edited by
        #3

        Thank you!!! and another question: How can I check if the key exist?

        SnaidiS(Semion)

        P 1 Reply Last reply
        0
        • S Semion_N

          Thank you!!! and another question: How can I check if the key exist?

          SnaidiS(Semion)

          P Offline
          P Offline
          PJ Arends
          wrote on last edited by
          #4

          Semion_N wrote:

          How can I check if the key exist?

          Call Open() the way you did in your original post and check the returned error code. If the key does not exist Open() will fail with the return value of ERROR_FILE_NOT_FOUND. Sorry it took so long to respond, I am not getting any reply emails from CP:((


          You may be right
          I may be crazy
          -- Billy Joel --

          Within you lies the power for good, use it!!!

          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