c++ - 未解析的外部符号 _DEVPKEY_Device_BusReportedDeviceDesc

标签 c++ visual-studio linker driver setupapi

对于连接到我的机器的设备,我想检索设备属性总线报告的设备描述。为此,我使用函数 SetupDiGetDevicePropertySetup API .在 devpkey.h 中,我找到了定义 DEVPKEY_Device_BusReportedDeviceDesc

但是,如果我使用 DEVPKEY_Device_BusReportedDeviceDesc,我会在链接时收到未解析的外部符号 _DEVPKEY_Device_BusReportedDeviceDesc

这是我的代码(仅包含用于重现问题的最少代码):

#include "stdafx.h"

#include <Windows.h>
#include <devpropdef.h>
#include <devpkey.h>

int main()
{
    DEVPROPKEY x = DEVPKEY_Device_BusReportedDeviceDesc;

    return 0;
}

这是完整的错误代码:

error LNK2001: unresolved external symbol _DEVPKEY_Device_BusReportedDeviceDesc

我该如何解决这个问题?

最佳答案

要解决此问题,您需要包含 initguid.h。这包括必须在 devpropdef.hdevpkey.h 之前。

#include "stdafx.h"
#include <initguid.h>   // include before devpropdef.h
#include <Windows.h>
#include <devpropdef.h>
#include <devpkey.h>

int main()
{
    DEVPROPKEY x = DEVPKEY_Device_BusReportedDeviceDesc;

    return 0;
}

关于c++ - 未解析的外部符号 _DEVPKEY_Device_BusReportedDeviceDesc,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47714380/

相关文章:

c++ - 从 peter fillmore 编译 proxmark3 fork 时出错

c++ - 来自环形拓扑的全局最大值,而不是来自 C++ 中的 MPI_REDUCE

c# - 通过 ILMerge 合并 WCF 引用

c# - 自定义卸载操作c#

c - 最后加载 elf 部分后,闪存中存在其他数据

c - 如何解决这个C链接器错误?

c - 将 C 文件中的符号导入链接描述文件

C++ char变量2字

c++ - operator<< 重载如何工作?

android - Xamarin Forms 使用 Shell 菜单将选项卡栏更改为工具栏