title: Create a new windows registry key using c++
body: <p>I'm trying to create a new registry key in the windows registry using C++.  Here is the code I have so far:</p>
  
  <pre><code>HKEY hKey;
      LPCTSTR sk = TEXT("SOFTWARE\\OtherTestSoftware");
  
      LONG openRes = RegCreateKeyEx(
              HKEY_LOCAL_MACHINE,
              sk,
              0,
              NULL,
              REG_OPTION_BACKUP_RESTORE,
              KEY_ALL_ACCESS,
              NULL,
              &amp;hKey,
              NULL);
  
      if (openRes==ERROR_SUCCESS) {
          printf("Success creating key.");
      } else {
          printf("Error creating key.");
      }
  
      LPCTSTR value = TEXT("OtherTestSoftwareKey");
      LPCTSTR data = "OtherTestData\0";
  
      LONG setRes = RegSetValueEx (hKey, value, 0, REG_SZ, (LPBYTE)data, strlen(data)+1);
  
      if (setRes == ERROR_SUCCESS) {
          printf("Success writing to Registry.");
      } else {
          printf("Error writing to Registry.");
      }
  
      //RegDeleteKey(hKey, sk);
  
      LONG closeOut = RegCloseKey(hKey);
  
      if (closeOut == ERROR_SUCCESS) {
          printf("Success closing key.");
      } else {
          printf("Error closing key.");
      }
  </code></pre>
  
  <p>I'm able to successfully open an existing key using a very similar code snippet (basically replace RegCreateKeyEx with RegOpenKeyEx).  I would imagine that one or more of the arguments I'm passing into RegCreateKeyEx is causing the trouble.  I'm honestly not sure where things might be getting fouled up since all of the error codes i've trapped show success.  For reference, here is the function signature for RegCreateKeyEx:</p>
  
  <pre><code>/*
   * LONG WINAPI RegCreateKeyEx(
        __in        HKEY hKey,
        __in        LPCTSTR lpSubKey,
        __reserved  DWORD Reserved,
        __in_opt    LPTSTR lpClass,
        __in        DWORD dwOptions,
        __in        REGSAM samDesired,
        __in_opt    LPSECURITY_ATTRIBUTES lpSecurityAttributes,
        __out       PHKEY phkResult,
        __out_opt   LPDWORD lpdwDisposition
      );
   */
  </code></pre>
  
  <p>Any thoughts would be great!</p>
  
  <p>thanks,
  brian</p>