为什么我得到LNK2001未解析的符号\u IID\u IPortableDeviceManager

为什么我得到LNK2001未解析的符号\u IID\u IPortableDeviceManager,c,C,我正在尝试使用C枚举连接的设备,并在Windows 10上使用VS 2015编写代码 我的头文件如下所示: #pragma once #include <PortableDeviceApi.h> #include <stdio.h> #include <objbase.h> /* Asks the user what registry key he would like to get and then output the key to a file.

我正在尝试使用C枚举连接的设备,并在Windows 10上使用VS 2015编写代码

我的头文件如下所示:

#pragma once

#include <PortableDeviceApi.h>
#include <stdio.h>
#include <objbase.h>

/*
Asks the user what registry key he would like to get and then output the key to a file.

@param - None
@return - None
*/
void showDevices();
#include "DeviceHandler.h"

void showDevices()
{

    IPortableDeviceManager *deviceManager;
    HRESULT result;
    IID const *interfaceId =  &IID_IPortableDeviceManager;
    CLSID const *classId = &CLSID_PortableDeviceManager;

    deviceManager = malloc(sizeof(IPortableDeviceManager));

    result = CoCreateInstance(classId, NULL, CLSCTX_INPROC_SERVER, interfaceId, &deviceManager);

    if (result != S_OK)
    {
        wprintf(L"%s\n", L"Class failed to be created");
    }

    free(deviceManager);

    return;
}//end showDevices
我收到IID_IPortableDeviceManager和CLSID_PortableDeviceManager的链接错误

我查看了包含的PortableDeviceApi.h文件,这两个变量定义为:

EXTERN_C const CLSID CLSID_PortableDeviceManager;
EXTERN_C const IID IID_IPortableDeviceManager;

我需要做什么才能使链接器识别这些外部变量?

EXTERN_C const CLSID CLSID_PortableDeviceManager是一个声明,而不是一个定义。项目>属性>链接器>输入>其他依赖项设置的可能重复项,请添加PortableDeviceGuids.libThank you@Hans Passant,这样代码就可以编译而不会出现链接错误。
EXTERN_C const CLSID CLSID_PortableDeviceManager是一个声明,而不是一个定义。如果项目>属性>链接器>输入>其他依赖项设置可能重复,请添加PortableDeviceGuids.libThank you@Hans Passant,这样代码就可以在没有链接错误的情况下编译。