title: Error with function call CRegKey::QueryStringValue
body: <p>Today i found this strange error in querying the time zone information .
  The code to read the display name of time zones looks like this </p>
  
  <pre><code>typedef struct {
      LONG Bias;
      LONG StandardBias;
      LONG DaylightBias;
      SYSTEMTIME StandardDate;
      SYSTEMTIME DaylightDate;
  } TZI, * PTZI;
  
  CRegKey RegKey;
  CString regKey = _T("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones");
  int idx = 0;
  bool bMoreKeys = true;
  bool bSuccess = true;
  while (bMoreKeys &amp;&amp; bSuccess) {
      CString sSubkeyName;
      DWORD nLength = 200;
      LPTSTR sBuffer = sSubkeyName.GetBufferSetLength(nLength);
      FILETIME ftLastWriteTime;
      bMoreKeys = (RegKey.EnumKey(idx, sBuffer, &amp; nLength, &amp; ftLastWriteTime) == ERROR_SUCCESS);
      sSubkeyName.ReleaseBuffer();
      if (!bMoreKeys) {
          bMoreKeys = false;
          break;
      }
      CString sSubKeyPath = regKey + _T("\\") + sSubkeyName;
      CRegKey subKey;
      if (subKey.Open(HKEY_LOCAL_MACHINE, sSubKeyPath, KEY_READ) != ERROR_SUCCESS) {
          //LOG_ERROR
          bSuccess = false;
          break;
      }
      // Get the display name
      CString sDispName;
      DWORD nDispBufferLength = 1000;
      LPTSTR sDispBuffer = sDispName.GetBufferSetLength(nDispBufferLength);
      if (subKey.QueryStringValue(_T("Display"), sDispBuffer, &amp; nDispBufferLength) != ERROR_SUCCESS) {
          //LOG_ERROR
          bSuccess = false;
          break;
      }
      sDispName.ReleaseBuffer();
      // Get the Bias (for later sorting);
      TZI tzi;
      nLength = sizeof(tzi);
      if (subKey.QueryBinaryValue(_T("TZI"), &amp; tzi, &amp; nLength) != ERROR_SUCCESS &amp;&amp; nLength != sizeof(tzi)) {
          //LOG_ERROR
          bSuccess = false;
      }
      (void) subKey.Close();
      idx++;
  }
  </code></pre>
  
  <p>But for some of the time zones for eg : argentina  the return value is not error_success.
  On further debugging into the QueryStringValue , i found this </p>
  
  <pre><code>if ((nBytes % sizeof(TCHAR) != 0) || (pszValue[nBytes / sizeof(TCHAR) - 1] != 0)) {
      return ERROR_INVALID_DATA;
  }
  </code></pre>
  
  <p>and when the nBytes size is <strong>48</strong> for any time zone display value then <strong>always</strong> error_invalid_data is returned . </p>
  
  <p>To confirm this i have changed the regkey api call to </p>
  
  <pre><code>DWORD dwType = 0;
  ULONG nBytes = 256 * sizeof(TCHAR);
  TCHAR displayValue[256];
  if (subKey.QueryValue(
      _T("Display"), &amp; dwType, (LPBYTE) displayValue, &amp; nBytes) == 0 &amp;&amp; dwType == REG_SZ) {}
  </code></pre>
  
  <p>and i dont get the error anymore and everything is working fine .
  Couldnt find out any valid reason that why it occurs.Anyone has better explanation why for all the timezones with size 48 we get the invalid data error .
  Thanks in advance.</p>
  
  <p>EDIT:</p>
  
  <p>PS: In some machines everything is working well with the code mentioned above (i.e the first one) and in some other machines its not which is what really strange and with the second code everywhere i could see the code is working fine.</p>