• WDM驱动加载方式理解


    当PC得知有新设备插入时,总线驱动会创建相应的物理驱动PDO,然后提示有新设备插入,这时候调用相应Driver的AddDevice方法创建功能驱动FDO

    下面是一个典型的AddDevice方法

    #pragma PAGEDCODE
    NTSTATUS HelloWDMAddDevice(IN PDRIVER_OBJECT DriverObject,
                               IN PDEVICE_OBJECT PhysicalDeviceObject)
    { 
        PAGED_CODE();
        KdPrint(("Enter HelloWDMAddDevice
    "));
    
        NTSTATUS status;
        PDEVICE_OBJECT fdo;
        UNICODE_STRING devName;
        RtlInitUnicodeString(&devName,L"\Device\MyWDMDevice");
        status = IoCreateDevice(
            DriverObject,
            sizeof(DEVICE_EXTENSION),
            &(UNICODE_STRING)devName,
            FILE_DEVICE_UNKNOWN,
            0,
            FALSE,
            &fdo);
        if( !NT_SUCCESS(status))
            return status;
        PDEVICE_EXTENSION pdx = (PDEVICE_EXTENSION)fdo->DeviceExtension;
        pdx->fdo = fdo;
        pdx->NextStackDevice = IoAttachDeviceToDeviceStack(fdo, PhysicalDeviceObject);
        UNICODE_STRING symLinkName;
        RtlInitUnicodeString(&symLinkName,L"\DosDevices\HelloWDM");
    
        pdx->ustrDeviceName = devName;
        pdx->ustrSymLinkName = symLinkName;
        status = IoCreateSymbolicLink(&(UNICODE_STRING)symLinkName,&(UNICODE_STRING)devName);
    
        if( !NT_SUCCESS(status))
        {
            IoDeleteSymbolicLink(&pdx->ustrSymLinkName);
            status = IoCreateSymbolicLink(&symLinkName,&devName);
            if( !NT_SUCCESS(status))
            {
                return status;
            }
        }
    
        fdo->Flags |= DO_BUFFERED_IO | DO_POWER_PAGABLE;
        fdo->Flags &= ~DO_DEVICE_INITIALIZING;
    
        KdPrint(("Leave HelloWDMAddDevice
    "));
        return STATUS_SUCCESS;
    }

    细心的人也许会觉得这个方法的第二个参数PhysicalDeviceObject,即PDO,来的有些莫名其妙,没有交代类型等

    这个对象在inf可以指定它的类型,比如

    ServiceType=1

  • 相关阅读:
    JS—超酷时钟
    JS—简单年历表
    ZZULI 1783 简单的求和
    ZZULI 1788 小金刚的宝藏(01背包模板)
    HDU 5172 GTY's gay friends(BestCoder Round #29)
    HDU 2157 How many ways??
    HDU 5171 GTY's birthday gift(BestCoder Round #29)
    在SQL Server 中启用 FileStream
    (转载)SQL Server的一个不显眼的功能 备份文件的分割
    面向对象建模方法与数据库建模方法的比较
  • 原文地址:https://www.cnblogs.com/zwt1234/p/4618112.html
Copyright © 2020-2023  润新知