Author Topic: Visual Studio 2012 Desktop Linking Issue with HidD_GetHidGuid function  (Read 19943 times)

JKirk

  • Member
  • ***
  • Posts: 3
This has got me baffled.

I just downloaded Visual Express 2012 Desktop yesterday to use it to compile some HID code. I had lots of trouble trying to get it to build so I finally reduced it down to a minisule size.

If I can get this to build, then I think can take it from there.

The issue I'm having is a failure in the link step. It gets through the compile step fine, but the linker can't seem to be able to resolve the function call to "HidD_GetHidGuid".

I generated the project as a c++ Win32 console application.
I stick to c procedural type coding...I've never gotten my head around objects.
I guess Unicode is enabled...don't know if that makes a difference.
I have precompiled headers turned off.

Everything is in the following main Listen.cc module.
When I try try to build, two Link errors are generated...see below...

//*************************************
//Listen.cc
#include <stdio.h>
#include <tchar.h>
#include <windows.h>
#include <hidsdi.h>

LPGUID testit;
int _tmain(int argc, _TCHAR* argv[])
   HidD_GetHidGuid(testit);
   while(1) {
      printf("hello world");
   }
   return 0;
}

Error   1   error LNK2019: unresolved external symbol "void __stdcall HidD_GetHidGuid(struct _GUID *)" (?HidD_GetHidGuid@@YGXPAU_GUID@@@Z) referenced in function _wmain   H:\TestVisualStudio\Listen\Listen.obj   Listen
Error   2   error LNK1120: 1 unresolved externals   H:\TestVisualStudio\Listen\Debug\Listen.exe   Listen
//****************************************************************

If I comment out the "HidD_GetHidGuid" line, the program will build and run properly by filling the screen with "hello worlds".

I know the "HidD_GetHidGuid" is to be found in the "hid.lib" module.
I tried to add the module to the Linker "Additional Dependencies"...but that didn't work.

Or maybe I don't know how to add it correctly.
Or maybe that's not what is needed to solve this issue.

Any help or insight would be greatly appreciated...

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research

JKirk

  • Member
  • ***
  • Posts: 3
Re: Visual Studio 2012 Desktop Linking Issue with HidD_GetHidGuid function
« Reply #2 on: November 27, 2012, 12:33:09 am »
Thanks Jan for your speedy reply.

I read your post and had some success with the linked information...although not totally.

I changed the code to include the following suggestions:
....#define WINVER 0x0500
....extern "C"{#include <hidsdi.h>}

So now the code looks like this:
//******************************************************************
//Listen.cc
#define WINVER 0x0500       // minimum required: 0x0500
#include <stdio.h>
#include <tchar.h>
#include <windows.h>

extern "C"{
#include <hidsdi.h>
}

LPGUID test;
int _tmain(int argc, _TCHAR* argv[])
{
   HidD_GetHidGuid(test);
   while(1) {
      printf("hello world");
   }
   return 0;
}
//****************************************************************

Then I tried to add a path for hid.lib to the library search directorties.

Right off the bat I found that the suggested method of menu options: Tools | Options | Projects and Solutions | VC++ Directories...didn't work. Instead, it resulted in a VC++ Directories message in the dialog box that said it was  depricated.

Now the Visual Studio Express ver. 2012 Desktop options are: Project | Properties | Configuration Properties | VC++ Directories | Library Directories.

On my system, the full path of the 32bit and 64bit library directories where hid.lib resides are:
C:\Program Files (x86)\Windows Kits\8.0\Lib\win8\um\x64....and
C:\Program Files (x86)\Windows Kits\8.0\Lib\win8\um\x86.
This "Windows Kit" series of files came as part of the Visual Studio Express install.

I added one path...tested...then tried the other.
No luck on the 64bit path...in fact, besides the first error, I had 30 additional Link errors.
SUCCESS ON THE 32Bit PATH...it compiled and linked fine.

I also had a new copy of the Windows DDK that had a set of paths of its own.
So I tried both the 64bit and 32bit DDK library paths:
Again 31 Link errors on the 64bit library path...C:\WinDDK\7600.16385.1\lib\win7\ia64.
Again SUCCESS on the 32bit library path..........C:\WinDDK\7600.16385.1\lib\win7\i386.

Also, I did some testing and found that the...#define WINVER 0x0500...was not necessary for the compile to work.

But the...extern "C"{#include <hidsdi.h>}...WAS INDEED REQUIRED for the builds to work.

So I had 4 versions of the program that I tested...two different 32bit pid.lib files "with and without" a #define WINVER 0x0500.

Now the bad news...
In all four cases...the listen.exe program would crash immediately after starting.

I hadn't expected this type of outcome. In my mind the GUID should act like a file handle. What we are doing is grabbing the GUID and not doing anything with it...while "hello world" grinds away in an infinite loop.

If I'm not mistaken isn't this GUID really just a handle into the linked-list of the HID devices? Does Windows have some kind of timer on the use of this handle?

This has me scratching my head...but that's why I'm here...  8)

 

JKirk

  • Member
  • ***
  • Posts: 3
Re: Visual Studio 2012 Desktop Linking Issue with HidD_GetHidGuid function
« Reply #3 on: November 27, 2012, 01:57:24 pm »
OK...I made a stupid mistake.
My Bad was passing a pointer into a function before that pointer points to a anything valid. Creating the pointer by itself doesn't allocate the guid object in memory. All that is allocated is a pointer. And on creation that pointer points to random memory. So it throws a memory fault on execution...

//BAD...Leads to memory fault.
LPGUID test;
   HidD_GetHidGuid(test);

//GOOD..This is how it should be done.
GUID test;
   HidD_GetHidGuid(&test);

//Or this works....
GUID test:
LPGUID testptr:
   testptr = &test;
   HidD_GetHidGuid(testptr);

Now I don't crash.........
« Last Edit: November 27, 2012, 02:00:14 pm by JKirk »

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Visual Studio 2012 Desktop Linking Issue with HidD_GetHidGuid function
« Reply #4 on: November 27, 2012, 01:58:42 pm »
Excellent, thanks for reporting what you found.