jiangjun0130
驱动牛犊
驱动牛犊
  • 注册日期2013-12-11
  • 最后登录2013-12-13
  • 粉丝0
  • 关注0
  • 积分2分
  • 威望11点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
阅读:2590回复:2

Windows 无法加载这个硬件的设备驱动程序。驱动程序可能已损坏或不见了。 (代码 39)

楼主#
更多 发布于:2013-12-11 15:26
在安装sys驱动后出现的提示信息.不知道是inf文件的问题还是驱动代码本身的问题.
inf文件:

[Version]
Signature="$WINDOWS NT$"              
Class=USBFilter                  
ClassGuid={64D7F6DE-FDF0-466E-9FEA-38761E927309}
Provider=%ProviderName%              
DriverVer=12/06/2013,6.1.7600.16385
; ================= Class section =====================
[ClassInstall32]
Addreg=USBFilterClassReg    
[USBFilterClassReg]
HKR,,,0,%DeviceClassName%      
HKR,,Icon,,-18            
;*****************************************
; PnpPowerSample  Install Section
;*****************************************
[Manufacturer]
%MfgName%=Standard,NTx86      
; Following section is meant for Windows 2000 as it
; cannot parse decorated model sections
[Standard]
;
; Hw Id is root\USBFilter
;
%USBFilter.DeviceDesc%=USBFilter_Device, USB\VID_516&PID_24613
; Decorated model section take precedence over undecorated
; ones on XP and later.
[Standard.NTx86]
%USBFilter.DeviceDesc%=USBFilter_Device, USB\VID_516&PID_24613
[DestinationDirs]
USBFilter_Files_Driver = 12      
[USBFilter_Device.NT]
CopyFiles=USBFilter_Files_Driver
[USBFilter_Files_Driver]
WDKApp.sys
;-------------- Service installation
[USBFilter_Device.NT.Services]
AddService = USBFilter2,0x00000002, USBFilter_AddService
; -------------- USBFilter driver install sections
[USBFilter_AddService]
DisplayName    = %USBFilter.SVCDESC%  
ServiceType    = 1              
StartType      = 3              
ErrorControl   = 1              
ServiceBinary  = %12%\WDKApp.sys  ;
;--- WDF Coinstaller installation ----
;
[DestinationDirs]
CoInstaller_CopyFiles = 11

[USBFilter_Device.NT.CoInstallers]          ;CopyFiles=CoInstaller_CopyFiles
AddReg=CoInstaller_AddReg
[CoInstaller_CopyFiles]
WdfCoInstaller01007.dll
[CoInstaller_AddReg]
HKR,,CoInstallers32,0x00010000, "WdfCoInstaller01007.dll,WdfCoInstaller"
[USBFilter_Device.NT.Wdf]
KmdfService =  USBFilter2, USBFilter_wdfsect
[USBFilter_wdfsect]
KmdfLibraryVersion = 1.7

[Strings]
ProviderName="JJ"
MfgName="JJ"
DeviceClassName="WDF USBFilter Driver"
USBFilter.DeviceDesc = "USB Filter"
USBFilter.SVCDESC = "WDF USBFilter Service"
c++代码:
driver.c:

NTSTATUS DriverEntry(
IN PDRIVER_OBJECT DriverObject,
IN PUNICODE_STRING RegistryPath
)
{
 WDF_DRIVER_CONFIG  config;
 NTSTATUS    status = STATUS_SUCCESS; KdPrint(("USBFilter: DriverEntry - WDF version built on %s %s\n",
                            __DATE__, __TIME__));
 WDF_DRIVER_CONFIG_INIT(
  &config,
  USBFilter_EvtDeviceAdd     );
 config.EvtDriverUnload = USBFilter_EvtDriverUnload; status = WdfDriverCreate(
  DriverObject,
  RegistryPath,
  WDF_NO_OBJECT_ATTRIBUTES,
  &config,      ////这是WDF_DRIVER_CONFIG类型的变量
  WDF_NO_HANDLE
  );
 if(!NT_SUCCESS(status))
 {
  //
        // Framework will automatically cleanup on error Status return
        //
        KdPrint(("USBFilter: Error Creating WDFDRIVER 0x%x\n", status));
 } return status;
}
VOID USBFilter_EvtDriverUnload(
 _In_ WDFDRIVER Driver
 )
{
 KdPrint(("USBFilter: USBFilter_EvtDriverUnload\n"));
 return;
}
device.c:

NTSTATUS USBFilter_EvtDeviceAdd(
 IN WDFDRIVER  Driver,
 IN PWDFDEVICE_INIT DeviceInit
 )
{
 WDF_PNPPOWER_EVENT_CALLBACKS  pnpPowerCallbacks;
 WDF_OBJECT_ATTRIBUTES    attributes;
 NTSTATUS       status;
 WDFDEVICE       device;
    WDF_IO_QUEUE_CONFIG     ioQueueConfig;
 WDF_OBJECT_ATTRIBUTES    queueAttributes;
 WDFQUEUE       queue; KdPrint(("USBFilter: USBFilter_EvtDeviceAdd - WDF version built on %s %s\n",
                            __DATE__, __TIME__));
  UNREFERENCED_PARAMETER(Driver);
    PAGED_CODE();
 //声明这是过滤器驱动程序
 WdfFdoInitSetFilter(DeviceInit);  // Initialize the WDF_PNPPOWER_EVENT_CALLBACKS structure
 WDF_PNPPOWER_EVENT_CALLBACKS_INIT(&pnpPowerCallbacks);
 //设置即插即用基本例程
 pnpPowerCallbacks.EvtDevicePrepareHardware = USBFilter_EvtDevicePrepareHardware;  //获取资源配置例程
 pnpPowerCallbacks.EvtDeviceReleaseHardware = USBFilter_EvtDeviceReleaseHardware;  //删除资源配置历程
 //在PCI和USB设备中,这两个基本即插即用例程,必须配置,以获取资源配置和释放资源
 //pnpPowerCallbacks.EvtDeviceSurpriseRemoval = USBFilter_EvtDevicePrepareHardware;  //设备意外拔除时的调用例程 //设置电源管理例程
 pnpPowerCallbacks.EvtDeviceD0Entry = USBFilter_EvtDeviceD0Entry;      //进入正常工作电源D0状态的调用例程
 pnpPowerCallbacks.EvtDeviceD0Exit = USBFilter_EvtDeviceD0Exit;       //退出工作电源D0状态的调用例程
 WdfDeviceInitSetPnpPowerEventCallbacks(
  DeviceInit,
  &pnpPowerCallbacks
  ); // This driver uses buffered I/O.
 WdfDeviceInitSetIoType(
  DeviceInit,
  WdfDeviceIoBuffered
  );
 // Specify the device object's context space by
    // using a driver-defined DEVICE_CONTEXT structure.
 WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(
  &attributes,
  DEVICE_CONTEXT
  );
 //Create the device object.
 status = WdfDeviceCreate(
  &DeviceInit,
  &attributes,
  &device); if(!NT_SUCCESS(status))
 {
   KdPrint(("WdfDeviceCreate failed 0x%x\n", status));
  return status;
 }
 
 //这是一个默认的queue
 WDF_IO_QUEUE_CONFIG_INIT_DEFAULT_QUEUE(
  &ioQueueConfig,
  WdfIoQueueDispatchSequential
  );
 //自定义队列的读操作和写操作
 ioQueueConfig.EvtIoRead = USBFilter_EvtIoRead;
 ioQueueConfig.EvtIoWrite = USBFilter_EvtIoWrite;
 ioQueueConfig.EvtIoDeviceControl = USBFilter_EvtIoDeviceControl;
 // Fill in a callback for destroy, and our QUEUE_CONTEXT size
 WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&attributes,QUEUE_CONTEXT);
 //attributes.EvtDestroyCallback = ; //创建队列
 status = WdfIoQueueCreate(
  device,
  &ioQueueConfig,
  &attributes,
  &queue);
 if (!NT_SUCCESS(status))
  {
        KdPrint(("WdfIoQueueCreate failed  %!STATUS!\n", status));
        return status;
  }
 return status;
}
 NTSTATUS USBFilter_EvtDevicePrepareHardware(
 IN WDFDEVICE  Device,
 IN WDFCMRESLIST  ResourceList,
 IN WDFCMRESLIST  ResourceListTranslated
 )
{
 KdPrint(("USBFilter: NTSTATUS USBFilter_EvtDevicePrepareHardware - WDF version built on %s %s\n",
                            __DATE__, __TIME__));
 return STATUS_SUCCESS;
}
NTSTATUS USBFilter_EvtDeviceReleaseHardware(
 IN WDFDEVICE  Device,
 IN WDFCMRESLIST  ResourceListTranslated
 )
{
 KdPrint(("USBFilter: NTSTATUS USBFilter_EvtDeviceReleaseHardware - WDF version built on %s %s\n",
                            __DATE__, __TIME__));
 return STATUS_SUCCESS;
}
NTSTATUS
USBFilter_EvtDeviceD0Entry(
    IN  WDFDEVICE Device,
    IN  WDF_POWER_DEVICE_STATE PreviousState
    )
{
 PDEVICE_OBJECT  deviceObject;
 PDRIVER_OBJECT  driverObject;
 PWCH  driverName;
 UNICODE_STRING  valueName; PAGED_CODE();
 DbgPrint("EvtDeviceD0Entry\n");
 RtlInitUnicodeString(&valueName,L"USBSTOR"); deviceObject = WdfDeviceWdmGetDeviceObject(Device);
 driverObject = deviceObject->AttachedDevice->DriverObject;
 driverName = driverObject->DriverName.Buffer;
    return STATUS_SUCCESS;
}NTSTATUS
USBFilter_EvtDeviceD0Exit(
    IN  WDFDEVICE Device,
    IN  WDF_POWER_DEVICE_STATE TargetState
    )
{
 PAGED_CODE();
 DbgPrint("EvtDeviceD0Exit\n");
    return STATUS_SUCCESS;
}
VOID USBFilter_EvtIoDeviceControl(
    IN WDFQUEUE   Queue,
    IN WDFREQUEST Request,
    IN size_t     OutputBufferLength,
    IN size_t     InputBufferLength,
    IN ULONG      IoControlCode
    )
{
 KdPrint(("!FUNC! Queue 0x%p, Request 0x%p OutputBufferLength %d InputBufferLength %d IoControlCode %d",
                Queue, Request, (int) OutputBufferLength, (int) InputBufferLength, IoControlCode));
    //WdfRequestCompleteWithInformation(Request, STATUS_INVALID_DEVICE_REQUEST, 0);
  WdfRequestComplete(Request, STATUS_SUCCESS);
    return;
}VOID USBFilter_EvtIoWrite(
    IN WDFQUEUE Queue,
    IN WDFREQUEST Request,
    IN size_t Length
    )
{
 //UsbSamp_DbgPrint(1, ("ISO transfer is not supported for buffered I/O transfer\n"));
 KdPrint(("!FUNC! Queue 0x%p, Request 0x%p Length %d",Queue,Request,(int)Length));
   // WdfRequestCompleteWithInformation(Request, STATUS_INVALID_DEVICE_REQUEST, 0);
 WdfRequestComplete(Request, STATUS_SUCCESS);
    return;
}
VOID USBFilter_EvtIoRead(
    IN WDFQUEUE queue,
    IN WDFREQUEST Request,
    IN size_t length
    )
{
 //UsbSamp_DbgPrint(1, ("ISO transfer is not supported for buffered I/O transfer\n"));
 KdPrint(("!FUNC! Queue 0x%p, Request 0x%p Length %d",queue,Request,(int)length));
   // WdfRequestCompleteWithInformation(Request, STATUS_INVALID_DEVICE_REQUEST, 0);
 WdfRequestComplete(Request, STATUS_SUCCESS);    return;
}
pengxiao618
驱动牛犊
驱动牛犊
  • 注册日期2013-07-17
  • 最后登录2016-05-25
  • 粉丝0
  • 关注0
  • 积分6分
  • 威望61点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
沙发#
发布于:2014-02-21 14:16
这种问题一般是下面的原因
[CoInstaller_CopyFiles]
WdfCoInstaller01007.dll
这个DLL文件要复制到sys文件所在的文件夹,然后对应不同的操作系统(XP,WIN7),这个
dll文件不同,建议选用WDK安装文件夹下的dll文件
pengxiao618
驱动牛犊
驱动牛犊
  • 注册日期2013-07-17
  • 最后登录2016-05-25
  • 粉丝0
  • 关注0
  • 积分6分
  • 威望61点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
板凳#
发布于:2014-07-23 17:48
游客

返回顶部