如何从客户端应用程序访问KMDF驱动程序

时间:2013-01-19 22:14:30

标签: kmdf

我已经编写了一个示例KMDF驱动程序。我不知道我是否做了所有事情,但已经看到KMDF驱动程序在DebugView实用程序中打印调试消息 - 当我将此驱动程序添加为新硬件时。它还在设备管理器下显示为“Sample Device”。

现在我想编写一个可以调用此驱动程序的示例客户端 - 这样我就可以在驱动程序和客户端之间建立连接。我读到我们需要使用'CreateFile'和'DEviceIOControl'等。但是我无法开始使用它。

您能否指导我创建示例客户端以访问示例KMDF驱动程序?

我的驱动程序的INF文件如下所示: -

    ***My INF FILE****
; myshelldriver.INF
; Windows installation file for installing the myshelldriver driver
; Copyright (c) Microsoft Corporation All rights Reserved
;
; Installation Notes:
;
;     Using Devcon: Type "devcon install myshelldriver.inf myshelldriver" to install
;

[Version]
Signature="$WINDOWS NT$"
Class=Sample
ClassGuid={78A1C341-4539-11d3-B88D-00C04FAD5171}
Provider=%MSFT%
DriverVer=09/24/2012,1.0
CatalogFile=myshell.cat

[DestinationDirs]
DefaultDestDir = 12

[ClassInstall32]
Addreg=SampleClassReg

[SampleClassReg]
HKR,,,0,%ClassName%
HKR,,Icon,,-5

[DiskCopyfiles]
wdfmyshelldriver.sys

[SourceDisksNames]
1=%InstDisk%,

[SourceDisksFiles]
Wdfmyshelldriver.sys=1

[Manufacturer]
%MSFT% = DiskDevice,NTAMD64

; For Win2K
[DiskDevice]
%DiskDevDesc% = DiskInstall, wdfmyshelldriver

; For XP and later
[DiskDevice.NTAMD64]
%DiskDevDesc% = DiskInstall, wdfmyshelldriver

[DiskInstall.NT]
CopyFiles = DiskCopyfiles


;;specify that this is the installation
;;for nt based systems.
[DriverInstall.ntx86]
DriverVer=09/24/2012,1.0
CopyFiles=DriverCopyFiles


[DiskInstall.NT.Services]
AddService = wdfmyshelldriver, %SPSVCINST_ASSOCSERVICE%, DiskServiceInst

[DiskServiceInst]
ServiceType   = %SERVICE_KERNEL_DRIVER%
StartType     = %SERVICE_DEMAND_START%
ErrorControl  = %SERVICE_ERROR_NORMAL%
DisplayName   = %DiskServiceDesc%
ServiceBinary = %12%\Wdfmyshelldriver.sys
AddReg        = DiskAddReg

[DiskAddReg]
HKR, "Parameters", "BreakOnEntry",      %REG_DWORD%, 0x00000000
HKR, "Parameters", "DiskSize",          %REG_DWORD%, 0x00100000
HKR, "Parameters", "DriveLetter",       %REG_SZ%,    "R:"
HKR, "Parameters", "RootDirEntries",    %REG_DWORD%, 0x00000200
HKR, "Parameters", "SectorsPerCluster", %REG_DWORD%, 0x00000002




[Strings]
MSFT            = "Microsoft"
ClassName       = "My Shell Device"
DiskDevDesc     = "WDF My Shell Driver"
DiskServiceDesc = "myshelldriver Driver"
InstDisk        = "myshelldriver Install Disk"
;*******************************************
;Handy macro substitutions (non-localizable)
SPSVCINST_ASSOCSERVICE = 0x00000002
SERVICE_KERNEL_DRIVER  = 1
SERVICE_DEMAND_START   = 3
SERVICE_ERROR_NORMAL   = 1
REG_DWORD              = 0x00010001
REG_SZ                 = 0x00000000


**** END OF INF FILE***

2 个答案:

答案 0 :(得分:0)

WDK中有许多相关样本。例如,请查看KMDF Echo sample

答案 1 :(得分:0)

首先,您需要为对象命名。 其次,您需要至少执行以下一项操作:

  1. 在\ GLOBAL ?? \
  2. 中创建符号链接
  3. 注册设备接口。
  4. 选项1可以让你做简单的

    CreateFile("\\\\.\\<device_name>, ...);
    

    选项2,您需要使用Setup DI Api例程找到要打开它的设备。