title: RegSetValueEx returns success, but registry values not updating in regedit
body: <p>I've read numerous posts, but none seem to apply to the issue I'm experiencing.</p>
  
  <p>First off, I inherited the current registry values, hence I'm forced to use KEY_WOW64_32KEY.  (64-bit app writing to the 32-bit registry)</p>
  
  <p>Here is what I'm experiencing, from my C++ code: If I set a registry value (with the code below) and then get the registry value (with the code below), it appears to work fine (my 'get' equals my 'set').</p>
  
  <p>But when I open regedit (32-bit version) the value is not getting updated.  I even checked regedit (64-bit version) and the value is not even there (as expected).</p>
  
  <p>Thank you to the first responder - I have incorporated those suggestions and posted a rewrite; and for the sake of debugging I put in some hard coded values (just before the call to RegSetValueEx).  These will be removed once I figure this out.</p>
  
  <p>Note that all this code executes just fine and returns ERROR_SUCCESS.</p>
  
  <p>So, just to reiterate my question: why is regedit not updating with the values used by my RegSetValueEx?</p>
  
  <p>BTW - I played with RegFlushKey, but no difference.  Also, I am compiling with UNICODE.  What am I missing?</p>
  
  <pre><code>/************************************************************************************
  ************************************************************************************/
  LRESULT PWRegistry::SetValue(HKEY hKey, const std::wstring&amp; sSubKey, const std::wstring&amp; sName, const std::wstring&amp; sValue)
  {
      //  Init locals
      HKEY hRegKey(nullptr);
      DWORD dwAccess(KEY_WRITE | KEY_WOW64_32KEY);    //  Set in the 32-bit registry
      LRESULT result(ERROR_SUCCESS);
      DWORD dwSize = (DWORD)((sValue.length() + 1) * sizeof(wchar_t));
  
      //  Open the key
      result = RegOpenKeyEx(hKey, sSubKey.c_str(), 0, dwAccess, &amp;hRegKey);
      if (result != ERROR_SUCCESS)
      {
          //  Create it
          if (ERROR_SUCCESS != RegCreateKey(hKey, sSubKey.c_str(), &amp;hRegKey))
          {
              return result;
          }
      }
  
      //  Hardcode some values during debugging
      TCHAR tcName[] = L"APP_ABBR";
      TCHAR tcValue[] = L"TLM";
      dwSize = (DWORD)((lstrlen(tcValue) + 1) * sizeof(TCHAR)); // This equals 8
  
      //  Set the value
      result = RegSetValueEx(hRegKey, tcName, 0, REG_SZ, (BYTE*)tcValue, dwSize);
  
      if (hRegKey!= nullptr)
      {
          RegCloseKey(hRegKey);
      }
  
      return result;
  }
  
  /************************************************************************************
  ************************************************************************************/
  LRESULT PWRegistry::GetValue(HKEY hKey, LPCTSTR lpszSubKey, LPCTSTR lpszValueName, DWORD dwType, LPBYTE pData, DWORD dwDataSize)
  {
      DWORD dwOptions(0);
      DWORD dwAccess(KEY_QUERY_VALUE | KEY_WOW64_32KEY);  //  Get from the 32-bit registry
  
      HKEY hRegKey(nullptr);
      LRESULT result = RegOpenKeyEx(hKey, lpszSubKey, dwOptions, dwAccess, &amp;hRegKey);
  
      if (result == ERROR_SUCCESS)
      {
          result = RegQueryValueEx(hRegKey, lpszValueName, NULL, &amp;dwType, (LPBYTE)pData, &amp;dwDataSize);
      }
  
      if (hRegKey != NULL)
      {
          RegCloseKey(hRegKey);
      }
  
      return result;
  }
  
  </code></pre>