windows 函数DriverEntry中引用的未解析外部符号WdmlibIoCreateDeviceSecure

pqwbnv8z  于 2023-05-30  发布在  Windows
关注(0)|答案(1)|浏览(191)

我写了一个Windows 10驱动程序。下面是代码,实际上代码是一本书的样本。
有没有人知道我应该怎么处理这个问题。

#include <ntifs.h>
#include <wdmsec.h>

PDEVICE_OBJECT g_cdo = NULL;

const GUID  CWK_GUID_CLASS_MYCDO =
{ 0x17a0d1e0L, 0x3249, 0x12e1, {0x92,0x16, 0x45, 0x1a, 0x21, 0x30, 0x29, 0x06} };

#define CWK_CDO_SYB_NAME    L"\\??\\slbkcdo_3948d33e"

void DriverUnload(PDRIVER_OBJECT driver)
{
    // ...
}

NTSTATUS DriverEntry(PDRIVER_OBJECT driver, PUNICODE_STRING reg_path)
{
    NTSTATUS status;
    ULONG i;
    UCHAR mem[256] = { 0 };

    UNICODE_STRING sddl = RTL_CONSTANT_STRING(L"D:P(A;;GA;;;WD)");
    UNICODE_STRING cdo_name = RTL_CONSTANT_STRING(L"\\Device\\cwk_3948d33e");
    UNICODE_STRING cdo_syb = RTL_CONSTANT_STRING(CWK_CDO_SYB_NAME);

    KdBreakPoint();

    status = IoCreateDeviceSecure(
        driver,
        0, &cdo_name,
        FILE_DEVICE_UNKNOWN,
        FILE_DEVICE_SECURE_OPEN,
        FALSE, &sddl,
        (LPCGUID)&CWK_GUID_CLASS_MYCDO,
        &g_cdo);
    if (!NT_SUCCESS(status))
        return status;

    // ...
    return STATUS_SUCCESS;
}

错误消息为:

LNK2019 unresolved external symbol WdmlibIoCreateDeviceSecure referenced in function DriverEntry    MyDriver7   C:\Users\xxx\source\repos\MyDriver7\MyDriver7\Source.obj
w8f9ii69

w8f9ii691#

你需要用Wdmsec.lib编译你的项目。
在Visual Studio中,右键单击项目并转到Configuration Properties > Linker > Input > Additional Dependencies并添加$(DDK_LIB_PATH)Wdmsec.lib
您的项目文件应该添加如下内容:

<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <Link>
       <AdditionalDependencies>$(DDK_LIB_PATH)wdmsec.lib;%(AdditionalDependencies)</AdditionalDependencies>
    </Link>
</ItemDefinitionGroup>

这同样适用于其他平台。这是Debug, x64

相关问题