I am attempting to enumerate connected devices using C and writing the code with VS 2015 on Windows 10.
My header file looks like this:
#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();
My source code looks like this:
#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
I receive a linking error for both IID_IPortableDeviceManager and CLSID_PortableDeviceManager.
I looked through the PortableDeviceApi.h file that is included, and those two variables are defined as:
EXTERN_C const CLSID CLSID_PortableDeviceManager;
EXTERN_C const IID IID_IPortableDeviceManager;
What do I need to do to make the linker recognize these external variables?