title: Create new data in registry key?
body: <p>I just create new registry key called MyTestApp, and want to add new data in it, but don't know how.  So I have following code.</p>
  
  <pre><code>bool CreateSectionDataRegistry(CString sectionData, CString sectionValue)
  {
      HKEY hKey;      //registry key handle
      LONG lResult;   //result of registry operations
      DWORD dwType, dwSize=0;
  
      //try to open the key that we are currently pointing at with rootPath
      lResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE, rootPath + "\\" + "MyTestApp", NULL, KEY_ALL_ACCESS, &amp;hKey);
  
      if (lResult == ERROR_SUCCESS || lResult == ERROR_MORE_DATA)
      {
          //we have successfully opened the registry key. Now try to access the data
          lResult = RegQueryValueEx(HKEY_LOCAL_MACHINE, sectionData, 0, &amp;dwType, NULL, &amp;dwSize); 
  
          if(lResult == ERROR_SUCCESS || lResult == ERROR_MORE_DATA)
          {
                            //data already exists, so just return
              RegCloseKey(hKey);
              return true;
          }
          else//section data does not exist, so create new data
          {           
              DWORD dwDisposition;
              lResult = RegCreateKeyEx(HKEY_LOCAL_MACHINE, sectionData, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &amp;hKey, &amp;dwDisposition);
              RegCloseKey(hKey);
              return true;
          }   
      }
  
      return false;
  }
  </code></pre>
  
  <p>But when I trace down to the <code>RegCreateKeyEx()</code> call, it returns success but data is not created under the MyTestApp registry key or anywhere in the registry.  Am I using the correct function to create new data under MyTestApp.  Also from the argument above, I have <code>CString</code> sectionValue, so how do I check if I need to create data for <code>REG_SZ</code> or <code>REG_DWORD</code>?</p>
  
  <p>Thanks!</p>