static int
get_reg_subkeys (const ACE_TCHAR *key,
                 ACE_TCHAR *buffer,
                 DWORD &buf_len)
{
  HKEY hk;
  LONG rc = ACE_TEXT_RegOpenKeyEx (HKEY_LOCAL_MACHINE,
                                   key,
                                   0,
                                   KEY_READ,
                                   &hk);

  if (rc != ERROR_SUCCESS)
    return -1;

  ACE_TCHAR subkeyname[ACE_MAX_FULLY_QUALIFIED_NAME_LEN + 1];
  DWORD subkeyname_len = ACE_MAX_FULLY_QUALIFIED_NAME_LEN;
  FILETIME update_dummy;

  DWORD total = 0;

  for (int i = 0;
       (rc = ACE_TEXT_RegEnumKeyEx (hk, i,
                                    subkeyname,
                                    &subkeyname_len,
                                    0, 0, 0,
                                    &update_dummy)) != ERROR_NO_MORE_ITEMS;
        ++i)
    {
      if (subkeyname_len < buf_len - total)
        {
          ACE_OS::strcpy(buffer + total, subkeyname);
          total += subkeyname_len + 1;
          // Reset: was changed by RegEnumKeyEx call.
          subkeyname_len = ACE_MAX_FULLY_QUALIFIED_NAME_LEN + 1;
        }
      else
        return -1;
    }

  buf_len = total;

  ::RegCloseKey (hk);
  return 0;
}
Exemple #2
0
int
ACE_Registry::Binding_Iterator::Context_Iteration::next_n (u_long how_many,
                                                           Binding_List &list)
{
  // Make a copy
  u_long requested = how_many;

  // While there are more entries to be added to the list
  while (how_many > 0)
    {
      ACE_TCHAR string [ACE_Registry::Naming_Context::MAX_CONTEXT_NAME_SIZE];
      u_long size = sizeof string / sizeof (ACE_TCHAR);
      long result = ACE_TEXT_RegEnumKeyEx (this->parent_->naming_context (). key (),
                                           this->index_,
                                           string,
                                           &size,
                                           0,
                                           0,
                                           0,
                                           0);
      switch (result)
        {
        case ERROR_SUCCESS:
          // Object found
          {
            // Readjust counters
            this->index_++;
            how_many--;

            // Add to list
            // Create binding
            Binding binding (string, CONTEXT);
            // Add to binding list
            list.insert (binding);
          }
        // Continue to add to list
        break;

        case ERROR_NO_MORE_ITEMS:
          // Enumeration of objects complete

          /* FALL THROUGH */

        default:
          // Strange error

          // Reset index
          this->index_ = 0;
          // Current enumeration will become CONTEXTS
          this->parent_->current_enumeration (this->parent_->iteration_complete_);

          // If we were able to add contexts
          if (requested != how_many)
            return 0;
          else
            return -1;
        }
    }
  // If we reach here, all of <how_many> pairs were added to the list
  // Since more entries may be available
  // current enumeration will remain CONTEXTS
  return 0;
}
static int
get_reg_value (const ACE_TCHAR *key,
               const ACE_TCHAR *name,
               ACE_TCHAR *buffer,
               DWORD &buf_len,
               int all_subkeys = 0)
{
  HKEY hk;
  DWORD buf_type;
  LONG rc = ACE_TEXT_RegOpenKeyEx (HKEY_LOCAL_MACHINE,
                                   key,
                                   0,
                                   KEY_READ,
                                   &hk);

  if (rc != ERROR_SUCCESS)
    // print_error_string(ACE_LIB_TEXT ("RegOpenKeyEx"), rc);
    return -1;

  if (all_subkeys)
    {
      ACE_TCHAR ifname[ACE_MAX_FULLY_QUALIFIED_NAME_LEN + 1];
      DWORD ifname_len = ACE_MAX_FULLY_QUALIFIED_NAME_LEN + 1;
      FILETIME update_dummy;

      DWORD total = 0;
      DWORD size = buf_len;

      for (int i = 0;
           (rc = ACE_TEXT_RegEnumKeyEx (hk, i, ifname, &ifname_len,
                                        0, 0, 0,
                                        &update_dummy)) != ERROR_NO_MORE_ITEMS;
           ++i)
        {
          HKEY ifkey;
          if (rc != ERROR_SUCCESS
              || ACE_TEXT_RegOpenKeyEx (hk, ifname, 0,
                                        KEY_READ, &ifkey) != ERROR_SUCCESS)
            continue;

          if (ACE_TEXT_RegQueryValueEx (ifkey, name, 0, 0,
                                        (u_char*) (buffer + total),
                                        &size) != ERROR_SUCCESS)
            {
              RegCloseKey(ifkey);
              continue;
            }
          else
            {
              total += size;
              size = buf_len - total;
            }
          // Needs to be reset.
          ifname_len = ACE_MAX_FULLY_QUALIFIED_NAME_LEN + 1;
        }

      if (total == 0)
        {
          ::RegCloseKey (hk);
          return -2;
        }
      else
        {
          buf_len = total;
        }
    }
  else
    {

      rc = ACE_TEXT_RegQueryValueEx (hk,
                                     name,
                                     0,
                                     &buf_type,
                                     (u_char *) buffer,
                                     &buf_len);
      if (rc != ERROR_SUCCESS)
        {
          // print_error_string(ACE_LIB_TEXT ("RegEnumKeyEx"), rc);
          RegCloseKey (hk);
          return -2;
        }
    }

  ::RegCloseKey (hk);
  return 0;
}