我正在使用 Visual Studio 2019 为 Windows 10 创建 KMDF 驱动程序。在调查时,我看到多个项目使用称为 DMF 的东西。那些其他项目 example 将说明以下如何使用此外部库。
Step 3: Clone the Driver Module Framework (DMF) into the same parent directory.
Build the DmfK project with Release and Debug configurations for all architectures (x64 and Win32).
现在我不确定为什么它需要在同一个父目录中(假设我的 KMDF 驱动程序)。但我将它克隆到同一个目录,然后为所有架构构建了 4 次。现在,在我上面链接的
example
的代码中,我注意到与“Dmf”相关的唯一#include
语句是#include <DmfModules.Library.h>
,这是我的问题的来源,因为它是如何工作的?由于我在链接 DLL 和 LIB 文件方面的经验有限,我执行了以下操作来访问 DMF 的 api。
* 1.0 Properties -> Configuration Properties -> C/C++ -> General -> Additonal Include Directories -> then add C:\Users\me\source\repos\KMDF\DMF\Dmf\Framework
* 1.1 Properties -> Configuration Properties -> C/C++ -> General -> Additonal Include Directories -> then add C:\Users\me\source\repos\KMDF\DMF\Dmf\Modules.Library
* 1.2 Properties -> Configuration Properties -> C/C++ -> General -> Additonal Include Directories -> then add C:\Users\me\source\repos\KMDF\DMF\Dmf\Modules.Library.Tests
* 1.3 Properties -> Configuration Properties -> C/C++ -> General -> Additonal Include Directories -> then add C:\Users\me\source\repos\KMDF\DMF\Dmf\Modules.Template
* 2. Properties -> Configuration Properties -> Linker -> General -> Additonal Library Directories -> then add C:\Users\me\source\repos\KMDF\DMF\Release\x64\lib\DmfK
* 3. Properties -> Configuration Properties -> Linker -> Input -> Additonal Dependencies -> DmfK.lib
现在我确定我不需要包括 C/C++ -> General 中的所有内容,但我只是确保我涵盖了我的基础。无论如何,我可以直接包含我想要的标题,例如
#include "DmfDefinitions.h"
和 #include "Dmf_BufferQueue.h"
似乎确实有效。但是,当我尝试构建我以前工作的驱动程序时,问题出现了,我会收到 200 多个错误,这些错误全部源自随机头文件以及 Dmf 特定头文件。例如,这是我收到的许多错误中的一些。
Severity Code Description Project File Line Suppression State
Error (active) E1389 redeclaration cannot add dllexport/dllimport to "WdmlibRtlInitUnicodeStringEx" (declared at line 417 of "C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\km\wdmsec.h") KMDF C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\km\ntifs.h 2417
Error C2371 'PEPROCESS': redefinition; different basic types KMDF C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\km\ntifs.h 85
Error C2371 'PETHREAD': redefinition; different basic types KMDF C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\km\ntifs.h 86
Error C2375 'WdmlibRtlInitUnicodeStringEx': redefinition; different linkage KMDF C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\km\ntifs.h 2417
Error C2061 syntax error: identifier 'BufferPool_SourceSettings' KMDF C:\Users\me\source\repos\KMDF\DMF\Dmf\Modules.Library\Dmf_BufferQueue.h 43
Error C2059 syntax error: '}' KMDF C:\Users\me\source\repos\KMDF\DMF\Dmf\Modules.Library\Dmf_BufferQueue.h 47
Error C2143 syntax error: missing ')' before '*' KMDF C:\Users\me\source\repos\KMDF\DMF\Dmf\Modules.Library\Dmf_BufferQueue.h 56
Error C2143 syntax error: missing '{' before '*' KMDF C:\Users\me\source\repos\KMDF\DMF\Dmf\Modules.Library\Dmf_BufferQueue.h 56
Error C2059 syntax error: ')' KMDF C:\Users\ME\source\repos\KMDF\DMF\Dmf\Modules.Library\Dmf_BufferQueue.h 57
请注意,这只是当我尝试使用 Dmf 中的任何 API 并且我的 C 文件或标头都没有任何错误或警告时出现的问题。我认为这是因为我包含 Dmf 的方法是错误的,因为示例包含语句只是
<DmfModules.Library.h>
但我不知道如何执行此操作才能使用 Dmf 正确构建我的驱动程序。