title: Unable to read certain registry keys in C
body: <p>I'm using RegOpenKeyEx() and RegQueryValueEx() to try and get the value for six keys in the Windows registry. I'm able to do it for four of the six but am failing on certain others.</p>
  
  <pre><code>wchar_t * getRegKeyValue(HKEY rootKeyToGet, LPCWSTR subKeyToGet, LPCWSTR valueToGet)
  {
      HKEY resultHKey = 0;
      wchar_t resultString[255] = L"";
      DWORD dwType = REG_SZ;
      DWORD resultSize = 255;
  
      // See if the subkey exists. If it does, get its value.
      if (RegOpenKeyEx(rootKeyToGet, subKeyToGet, NULL, KEY_ALL_ACCESS, &amp;resultHKey) == ERROR_SUCCESS)
      {
          RegQueryValueEx(resultHKey, valueToGet, NULL, &amp;dwType, (LPBYTE) &amp;resultString, &amp;resultSize);
      }
  
      RegCloseKey(resultHKey);
      resultHKey = NULL;
  
      RegCloseKey(rootKeyToGet);
      rootKeyToGet = NULL;
  
      return resultString;
  }
  </code></pre>
  
  <p>The following are some successful calls:</p>
  
  <pre><code>swprintf(buffer, L"&amp;ie=%s", getRegKeyValue(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Internet Explorer", L"Version"));
  
  swprintf(buffer, L"&amp;os=%s.", getRegKeyValue(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", L"CurrentVersion"));
  
  wcscat(url, getRegKeyValue(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", L"CurrentBuild"));
  </code></pre>
  
  <p>Example of an unsuccessful call:</p>
  
  <pre><code>wcscpy(buffer, getRegKeyValue(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", L"CSDVersion"));
  </code></pre>
  
  <p>I'm able to open the key in the unsuccessful call but the query for that value returns an empty string. I'm running Visual Studio as an administrator. Have been scratching my head for the last day on where I am going wrong.</p>
  
  <p><strong>Update: The code returned is ERROR_FILE_NOT_FOUND. The codes are most definitely shown to exist in regedit.</strong></p>