UMDF驱动开发入门:二 详解INF文件与设备类选择
<p>在Windows驱动开发中,UMDF为用户模式驱动程序提供了一个安全稳定的开发框架。而INF文件作为驱动安装的核心,其正确配置对于驱动能否正常工作至关重要。这篇博客详细介绍UMDF驱动的INF文件配置,特别是设备类的选择与配置。实可以把INF文件理解为<strong>驱动的"安装说明书"</strong> - 它告诉Windows系统:</p><ul>
<li>
<p>这个驱动叫什么名字</p>
</li>
<li>
<p>应该安装到哪里</p>
</li>
<li>
<p>属于什么类型的设备</p>
</li>
<li>
<p>需要哪些文件</p>
</li>
</ul>
<p>微软Class详细说明地址:System-Defined Device Setup Classes Available to Vendors - Windows drivers | Microsoft Learn</p>
<h5 id="常见设备安装类速查表">常见设备安装类速查表</h5>
<table>
<thead>
<tr>
<th>Class Name</th>
<th>ClassGuid</th>
<th>简要说明</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>System</strong></td>
<td><code>{4d36e97d-e325-11ce-bfc1-08002be10318}</code></td>
<td><strong>软件设备或未指定类别的系统级设备</strong>,显示在设备管理器的"系统设备"下。</td>
</tr>
<tr>
<td><strong>SoftwareComponent</strong></td>
<td><code>{5c4c3332-344d-483c-8739-259e934c9cc8}</code></td>
<td><strong>软件组件</strong>,显示在"软件组件"下,适用于不关联特定硬件的驱动或软件更新。</td>
</tr>
<tr>
<td><strong>Biometric</strong></td>
<td><code>{53d29ef7-377c-4d14-864b-eb3a85769359}</code></td>
<td>生物识别设备,如指纹扫描器。</td>
</tr>
<tr>
<td><strong>Display</strong></td>
<td><code>{4d36e968-e325-11ce-bfc1-08002be10318}</code></td>
<td>显示适配器(显卡)。</td>
</tr>
<tr>
<td><strong>HIDClass</strong></td>
<td><code>{745a17a0-74d3-11d0-b6fe-00a0c90f57da}</code></td>
<td>人机接口设备,如键盘、鼠标等。</td>
</tr>
<tr>
<td><strong>Media</strong></td>
<td><code>{4d36e96c-e325-11ce-bfc1-08002be10318}</code></td>
<td>音频和视频设备,显示在"声音、视频和游戏控制器"下。</td>
</tr>
<tr>
<td><strong>Net</strong></td>
<td><code>{4d36e972-e325-11ce-bfc1-08002be10318}</code></td>
<td>网络适配器。</td>
</tr>
<tr>
<td><strong>Ports</strong></td>
<td><code>{4d36e978-e325-11ce-bfc1-08002be10318}</code></td>
<td>串行和并行端口。</td>
</tr>
<tr>
<td><strong>USB</strong></td>
<td><code>{36fc9e60-c465-11cf-8056-444553540000}</code></td>
<td>USB主机控制器和集线器。</td>
</tr>
<tr>
<td><strong>WPD</strong></td>
<td><code>{eec5ad98-8080-425f-922a-dabf3de3f69a}</code></td>
<td>Windows便携设备,如手机、媒体播放器。</td>
</tr>
</tbody>
</table>
<h5 id="inf文件驱动的身份证和说明书">INF文件:驱动的"身份证"和"说明书"</h5>
<p>INF文件其实就是个文本文件,但它包含了驱动安装所需的所有信息。主要完成四个任务:</p>
<ol>
<li>
<p><strong>自我介绍</strong> - 我叫什么,版本多少,谁开发的</p>
</li>
<li>
<p><strong>文件说明</strong> - 需要复制哪些文件,放到哪里</p>
</li>
<li>
<p><strong>设备分类</strong> - 我属于哪类设备(最重要!)</p>
</li>
<li>
<p><strong>服务注册</strong> - 如何启动和运行</p>
</li>
</ol>
<h2 id="解剖inf文件一看就懂的结构">解剖INF文件:一看就懂的结构</h2>
<h3 id="1-版本信息---身份证页">1. 版本信息 - "身份证页"</h3>
<pre><code class="language-ini">
Signature = "$WINDOWS NT$" // 固定写法,表示这是Windows驱动
Class = SampleDevice // 设备类型:决定在设备管理器哪里显示
ClassGuid = {GUID} // 设备类型的唯一编号
Provider = %ManufacturerName% // 开发商名称
DriverVer = 01/01/2024,1.0.0.0 // 驱动版本
CatalogFile = YourDriver.cat // 签名文件(安全相关)
</code></pre>
<p>微软Class详细说明地址:https://learn.microsoft.com/en-us/windows-hardware/drivers/install/system-defined-device-setup-classes-available-to-vendors</p>
<h3 id="2文件管理---附件清单-源文件节sourcedisksnamesfiles">2.文件管理 - "附件清单" 源文件节(SourceDisksNames/Files)</h3>
<pre><code class="language-ini">
1 = %DiskName%,,,"" // 磁盘标签
YourDriver.dll = 1,, // 驱动文件在哪
YourDriver.DriverFiles = 12// 驱动文件安装到System32\drivers
</code></pre>
<h3 id="3设备安装---安装步骤-设备安装节device-installation">3.设备安装 - "安装步骤" 设备安装节(Device Installation)</h3>
<pre><code class="language-ini">
%ManufacturerName% = MyCompany,ntamd64// 厂商信息
%DeviceName% = YourDevice_Install, Root\YourDevice// 设备名称和ID
Include = umdf.inf // 引用UMDF标准安装步骤
Needs = UmdfDriverEntry // 需要UMDF驱动入口
CopyFiles = YourDriver.DriverFiles //ceInstall
</code></pre>
<h3 id="设备类的选择">设备类的选择</h3>
<p>对于不涉及真实硬件的开发,主要就是两个选择:</p>
<h3 id="system类---虚拟硬件">System类 - "虚拟硬件"</h3>
<p><strong>把它想象成:创建一个虚拟的设备</strong></p>
<pre><code class="language-ini">
Class = System
ClassGuid = {4d36e97d-e325-11ce-bfc1-08002be10318}
</code></pre>
<p><strong>适合场景:</strong></p>
<ul>
<li>
<p>虚拟串口(让软件以为有额外的COM端口)</p>
</li>
<li>
<p>虚拟摄像头(视频会议软件的虚拟摄像头)</p>
</li>
<li>
<p>测试设备(模拟各种硬件进行测试)</p>
</li>
</ul>
<p><strong>特点:</strong></p>
<ul>
<li>
<p>在"设备管理器"→"系统设备"中显示</p>
</li>
<li>
<p>应用程序可以用<code>CreateFile</code>打开设备</p>
</li>
<li>
<p>支持所有Windows版本</p>
</li>
</ul>
<h3 id="softwarecomponent类---纯软件服务">SoftwareComponent类 - "纯软件服务"</h3>
<p><strong>把它想象成:安装一个系统服务组件</strong></p>
<pre><code class="language-ini">
Class = SoftwareComponent
ClassGuid = {5c4c3332-344d-483c-8739-259e934c9cc8}
</code></pre>
<p><strong>适合场景:</strong></p>
<ul>
<li>
<p>音频处理插件(音效增强、降噪)</p>
</li>
<li>
<p>视频解码器(支持新的视频格式)</p>
</li>
<li>
<p>AI推理引擎(图像识别、语音处理)</p>
</li>
<li>
<p>安全服务组件(加密、验证服务)</p>
</li>
</ul>
<p><strong>特点:</strong></p>
<ul>
<li>
<p>在"设备管理器"→"软件组件"中显示</p>
</li>
<li>
<p>通过专用API调用,不直接"打开设备"</p>
</li>
<li>
<p>只支持Windows 10及以上版本</p>
</li>
</ul>
<h2 id="实际项目选择指南">实际项目选择指南</h2>
<h3 id="场景1开发虚拟串口">场景1:开发虚拟串口</h3>
<pre><code class="language-context">需求:让串口调试工具能连接到一个虚拟的COM端口
选择:System类
原因:串口工具期望用CreateFile("COM3")这种方式打开设备
</code></pre>
<h3 id="场景2开发音频特效插件">场景2:开发音频特效插件</h3>
<pre><code class="language-context">需求:为系统音频添加实时混响效果
选择: SoftwareComponent类
原因:这是音频处理服务,通过音频API集成,不是独立的"设备"
</code></pre>
<h3 id="场景3开发usb设备模拟器">场景3:开发USB设备模拟器</h3>
<pre><code class="language-context">需求:模拟一个USB键盘,让系统认为插入了真实键盘
选择:System类
原因:需要让系统检测到"硬件设备"存在
</code></pre>
<h3 id="场景4开发ai图像识别服务">场景4:开发AI图像识别服务</h3>
<pre><code class="language-context">需求:提供图像识别能力,供其他程序调用
选择: SoftwareComponent类
原因:这是算法服务,应用程序应该通过API调用识别功能
</code></pre>
<p>强烈建议从<strong>System类</strong>开始,因为它的概念更直观,掌握了基础后,再学习SoftwareComponent类来开发更现代化的软件组件。</p><br><br>
来源:https://www.cnblogs.com/duwenlong/p/19158421
頁:
[1]