如何开发不接触硬件的Windows驱动程序?

发布于 2024-08-15 05:14:29 字数 1467 浏览 7 评论 0原文

我需要创建一个 WDM 驱动程序来模拟不存在的设备。操作系统启动时需要加载驱动程序,通过SetupDiXXXCreateFile打开和关闭,需要响应DeviceIoControl等。

我已经编码了驱动程序,但 XP 拒绝加载它。系统事件查看器显示:

MyDevice 服务失败 启动时出现以下错误: 服务也无法启动 因为它被禁用或者因为它 没有关联的已启用设备 它。

鉴于此,我认为问题出在 INF 文件中(参考如下)。是吗?我应该如何修复它?

;; MyDevice.inf

[Version]
Signature="$Windows 95$"

Class=MyDeviceDeviceClass
ClassGUID={ff646f80-8def-11d2-9449-00105a075f6b}
Provider=%ProviderName%
DriverVer= 12/21/2009,1.0.0.1

[ClassInstall32]
Addreg=Class_AddReg

[Class_AddReg]
HKR,,,,%DeviceClassName%
HKR,,Icon,,"-18"

[DestinationDirs]
MyDevice_Files_Driver = 10,System32\Drivers


[Manufacturer]
%MfgName%=Mfg0

[Mfg0]
%DeviceDesc%=MyDevice_DDI, *MyDevice


[MyDevice_DDI]
CopyFiles=MyDevice_Files_Driver
AddReg=MyDevice_9X_AddReg


[MyDevice_DDI.NT]
CopyFiles=MyDevice_Files_Driver
AddReg=MyDevice_NT_AddReg

[MyDevice_DDI.NT.Services]
Addservice = MyDevice, 0x00000002, MyDevice_AddService

[MyDevice_AddService]
DisplayName    = %SvcDesc%
ServiceType    = 1
StartType      = 3
ErrorControl   = 1
ServiceBinary  = %10%\System32\Drivers\MyDevice.sys

[MyDevice_NT_AddReg]
HKLM, "System\CurrentControlSet\Services\MyDevice\Parameters","BreakOnEntry", 0x00010001, 0

[MyDevice_Files_Driver]
MyDevice.sys


[Strings]
ProviderName="Acme"
MfgName="Acme"
DeviceDesc="Acme"
DeviceClassName="Device class for MyDevice"
SvcDesc="MyDevice NT service"

I need to create a WDM driver that emulates a device that is not present. The driver needs to be loaded when the O/S boots, opened and closed via SetupDiXXX and CreateFile, needs to respond to DeviceIoControl, etc.

I have the driver coded, but XP refuses to load it. The system event viewer says:

The MyDevice service failed to
start due to the following error: The
service cannot be started, either
because it is disabled or because it
has no enabled devices associated with
it.

Given that, I think the problem is in the INF file (reference below). Is it? How should I go about fixing it?

;; MyDevice.inf

[Version]
Signature="$Windows 95$"

Class=MyDeviceDeviceClass
ClassGUID={ff646f80-8def-11d2-9449-00105a075f6b}
Provider=%ProviderName%
DriverVer= 12/21/2009,1.0.0.1

[ClassInstall32]
Addreg=Class_AddReg

[Class_AddReg]
HKR,,,,%DeviceClassName%
HKR,,Icon,,"-18"

[DestinationDirs]
MyDevice_Files_Driver = 10,System32\Drivers


[Manufacturer]
%MfgName%=Mfg0

[Mfg0]
%DeviceDesc%=MyDevice_DDI, *MyDevice


[MyDevice_DDI]
CopyFiles=MyDevice_Files_Driver
AddReg=MyDevice_9X_AddReg


[MyDevice_DDI.NT]
CopyFiles=MyDevice_Files_Driver
AddReg=MyDevice_NT_AddReg

[MyDevice_DDI.NT.Services]
Addservice = MyDevice, 0x00000002, MyDevice_AddService

[MyDevice_AddService]
DisplayName    = %SvcDesc%
ServiceType    = 1
StartType      = 3
ErrorControl   = 1
ServiceBinary  = %10%\System32\Drivers\MyDevice.sys

[MyDevice_NT_AddReg]
HKLM, "System\CurrentControlSet\Services\MyDevice\Parameters","BreakOnEntry", 0x00010001, 0

[MyDevice_Files_Driver]
MyDevice.sys


[Strings]
ProviderName="Acme"
MfgName="Acme"
DeviceDesc="Acme"
DeviceClassName="Device class for MyDevice"
SvcDesc="MyDevice NT service"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

把回忆走一遍 2024-08-22 05:14:29

自我回答:

我更改了 INF 以包含以下内容:

[制造商0]
%DeviceDesc%=MyDevice_DDI, *MyDevice\ipm1

“\ipm1”是新的,在我眼中有点巫术。我从 Chris Cant 的“Writing Windows WDM Device Drvers”中的一个示例中得到了它。

最大的变化是使用控制面板中的“添加新硬件”向导来安装驱动程序。右键单击安装 INF 是不够的。我怀疑原因是它调用了 PnP 管理器,而该管理器无法正确找到驱动程序要控制的硬件。

Self answered:

I changed the INF to include the following:

[Mfg0]
%DeviceDesc%=MyDevice_DDI, *MyDevice\ipm1

The "\ipm1" is new, and a little voodoo in my eyes. I got it from an example in Chris Cant's "Writing Windows WDM Device Drvers".

The big change is using the "Add New Hardware" wizard from the control panel to install the driver. Right-click installing the INF is not enough. I suspect the reason is that it invokes the PnP manager which correctly fails to find hardware for the driver to control.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文