2

Upon using PKEY_Device_FriendlyName, I'm getting the following errors:

Error   1   error LNK2001: unresolved external symbol _PKEY_Device_FriendlyName DefaultAudioDeviceCPP.obj   
Error   2   fatal error LNK1120: 1 unresolved externals C:\Users\srobertson\Documents\Visual Studio 2005\Projects\DefaultAudioDeviceCPP\Debug\DefaultAudioDeviceCPP.exe 

What's a very simple way to clear these errors? I'm including functiondiscovery.h and functiondiscoverykeys.h. Also the path in Project->Properties...->Configuration Properties->C/C++->General->Additional Include Directories is correct.

EDIT: One thing of interest is that the errors are mentioning: _PKEY_Device_FriendlyName, not PKEY_Device_FriendlyName. But I'm only using the latter in my program.

Panzercrisis
  • 4,590
  • 6
  • 46
  • 85

3 Answers3

14

Old post, but hopefully this answer will save someone some time.

I was having the same problem with DEVPKEY properties - like DEVPKEY_Device_FriendlyName. I got a very similar link error. I stumbled upon the answer in comments here: Referencing GUIDs

Basically, add an #include before the include for things like devpkey.h where the property keys are defined.

So, at the top of my file I have:

#include <setupapi.h>  
#include <initguid.h>  // Put this in to get rid of linker errors.  
#include <devpkey.h>  // Property keys defined here are now defined inline.   
Community
  • 1
  • 1
GTAE86
  • 1,780
  • 3
  • 29
  • 39
2

An updated solution that worked for me, as per the microsoft docs

#include <functiondiscoverykeys.h>
KyleL
  • 855
  • 6
  • 24
0

PKEY_Device_FriendlyName resides in uuid.lib library. So you need to add a line to your source code:

#pragma comment(lib, "uuid.lib")

Most often, you can check with MSDN which library you need to reference.

Roman R.
  • 68,205
  • 6
  • 94
  • 158
  • 1
    I've tried adding it, but I'm getting kind of the same errors. – Panzercrisis Mar 19 '12 at 16:27
  • Other than that, you might be using old version of Windows SDK, which does not yet have this symbol. – Roman R. Mar 19 '12 at 16:29
  • At least 6.1 and 7.0 have this symbol. BTW Visual Studio 2005 is not supported/compatible by these latest SDK versions which makes me suspect you have them installed, but they are not used by compiler/linker. – Roman R. Mar 19 '12 at 16:31
  • do you by any chance also know which lib PKEY_AudioEndpoint_Disable_SysFx resides in? – serup Sep 19 '18 at 14:55
  • @serup I don't think it's in .lib but it's defined as GUID in such way that (see another answer here) should help. – Roman R. Sep 19 '18 at 15:35