ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

NTSTATUS NTAPI PcNewRegistryKey ( OUT PREGISTRYKEY OutRegistryKey,
IN PUNKNOWN OuterUnknown  OPTIONAL,
IN ULONG  RegistryKeyType,
IN ACCESS_MASK  DesiredAccess,
IN PVOID DeviceObject  OPTIONAL,
IN PVOID SubDevice  OPTIONAL,
IN POBJECT_ATTRIBUTES ObjectAttributes  OPTIONAL,
IN ULONG CreateOptions  OPTIONAL,
OUT PULONG Disposition  OPTIONAL 
)

Definition at line 275 of file registry.cpp.

Referenced by CMiniportWaveCMI::loadChannelConfigFromRegistry(), and CMiniportWaveCMI::storeChannelConfigToRegistry().

{
    HANDLE hHandle;
    NTSTATUS Status = STATUS_UNSUCCESSFUL;
    CRegistryKey * RegistryKey;
    PPCLASS_DEVICE_EXTENSION DeviceExt;
    PSUBDEVICE_DESCRIPTOR SubDeviceDescriptor;
    ISubdevice * Device;
    PSYMBOLICLINK_ENTRY SymEntry;
    BOOL CanDelete = FALSE;

    DPRINT("PcNewRegistryKey entered\n");

    if (!OutRegistryKey)
        return STATUS_INVALID_PARAMETER;

    if (RegistryKeyType != GeneralRegistryKey &&
        RegistryKeyType != DeviceRegistryKey &&
        RegistryKeyType != DriverRegistryKey &&
        RegistryKeyType != HwProfileRegistryKey &&
        RegistryKeyType != DeviceInterfaceRegistryKey)
    {
        return STATUS_INVALID_PARAMETER;
    }

    // check for the key type
    if (RegistryKeyType == GeneralRegistryKey)
    {
        // do we have the required object attributes
        if (!ObjectAttributes)
        {
            // object attributes is mandatory
            return STATUS_INVALID_PARAMETER;
        }
        // try to create the key
        Status = ZwCreateKey(&hHandle, DesiredAccess, ObjectAttributes, 0, NULL, CreateOptions, Disposition);

        // key can be deleted
        CanDelete = TRUE;
    }
    else if (RegistryKeyType == DeviceRegistryKey ||
             RegistryKeyType == DriverRegistryKey ||
             RegistryKeyType == HwProfileRegistryKey)
    {
        // check for HwProfileRegistryKey case
        if (RegistryKeyType == HwProfileRegistryKey)
        {
             // IoOpenDeviceRegistryKey used different constant
            RegistryKeyType = PLUGPLAY_REGKEY_CURRENT_HWPROFILE | PLUGPLAY_REGKEY_DEVICE;
        }

        // obtain the new device extension
        DeviceExt = (PPCLASS_DEVICE_EXTENSION) ((PDEVICE_OBJECT)DeviceObject)->DeviceExtension;

        Status = IoOpenDeviceRegistryKey(DeviceExt->PhysicalDeviceObject, RegistryKeyType, DesiredAccess, &hHandle);
    }
    else if (RegistryKeyType == DeviceInterfaceRegistryKey)
    {
        if (SubDevice == NULL)
        {
            // invalid parameter
            return STATUS_INVALID_PARAMETER;
        }

        // look up our undocumented interface
        Status = ((PUNKNOWN)SubDevice)->QueryInterface(IID_ISubdevice, (LPVOID*)&Device);

        if (!NT_SUCCESS(Status))
        {
            DPRINT("No ISubdevice interface\n");
            // invalid parameter
            return STATUS_INVALID_PARAMETER;
        }

        // get the subdevice descriptor
        Status = Device->GetDescriptor(&SubDeviceDescriptor);
        if (!NT_SUCCESS(Status))
        {
            DPRINT("Failed to get subdevice descriptor %x\n", Status);
            ((PUNKNOWN)SubDevice)->Release();
            return STATUS_UNSUCCESSFUL;
        }

        // is there an registered device interface
        if (IsListEmpty(&SubDeviceDescriptor->SymbolicLinkList))
        {
            DPRINT("No device interface registered\n");
            ((PUNKNOWN)SubDevice)->Release();
            return STATUS_UNSUCCESSFUL;
        }

        // get the first symbolic link
        SymEntry = (PSYMBOLICLINK_ENTRY)CONTAINING_RECORD(SubDeviceDescriptor->SymbolicLinkList.Flink, SYMBOLICLINK_ENTRY, Entry);

        // open device interface
        Status = IoOpenDeviceInterfaceRegistryKey(&SymEntry->SymbolicLink, DesiredAccess, &hHandle);

        // release subdevice interface
        ((PUNKNOWN)SubDevice)->Release();
    }

    // check for success
    if (!NT_SUCCESS(Status))
    {
        DPRINT1("PcNewRegistryKey failed with %lx\n", Status);
        return Status;
    }

    // allocate new registry key object
    RegistryKey = new(NonPagedPool, TAG_PORTCLASS)CRegistryKey(OuterUnknown, hHandle, CanDelete);
    if (!RegistryKey)
    {
        // not enough memory
        ZwClose(hHandle);
        return STATUS_INSUFFICIENT_RESOURCES;
    }

    // query for interface
    Status = RegistryKey->QueryInterface(IID_IRegistryKey, (PVOID*)OutRegistryKey);

    if (!NT_SUCCESS(Status))
    {
        // out of memory
        delete RegistryKey;
    }

    DPRINT("PcNewRegistryKey result %p\n", *OutRegistryKey);
    return STATUS_SUCCESS;
}

Generated on Sat May 26 2012 05:26:00 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.