Search code examples
cvisual-studio-2015hidwdkkmdf

Including hidpi.h in WDK Driver Causes Compilation Errors


I'm trying to modify the KMDF vhidmini2 sample from the Windows driver samples on Github (https://github.com/Microsoft/Windows-driver-samples/tree/97cf8edcaddff4fdbc5cc48d56b7d7eb2c39b749/hid/vhidmini2). One of my modifications requires including the hidpi.h header file. When I do this, however, I get compiler errors, the majority of which are:

identifier "USAGE" is undefined

along with a couple of:

redefinition: different type modifiers

as well as a number of syntax errors.

To try and seclude the error, I've tried compiling the vhidmini2 driver (which worked fine), and then inserting the include statement in the vhidmini.h file (which then causes the compilation to fail). Here's the include section of my modified vhidmini.h file; the rest of the code is untouched.

#ifdef _KERNEL_MODE
#include <ntddk.h>
#else
#include <windows.h>
#endif

#include <wdf.h>

#include <hidport.h>  // located in $(DDK_INC_PATH)/wdm
#include <Hidpi.h>

#include "common.h"

As an aside, I found a similar problem posted to Stack Overflow here: WDK (Windows Driver Kit) and VC++ headers problem. The solution to this problem seemed to be to tell Visual Studio to load WDK headers before loading SDK headers. The question is a few years old though, and Visual Studio 2015 does not allow the editing of VC++ Directories in the same way. If this is indeed the solution to my problem, how would one go about making this edit in the new Visual Studio? I've tried looking at the property sheets for the project, but the format is completely different.


Solution

  • I managed to fix the problem by replacing the line

    #include <Hidpi.h>
    

    with

    #include <hidsdi.h>
    

    My guess (based off of a similar problem answered here: Compile error in 'winbase.h') is that hidsdi.h includes in it some things that hidpi.h requires. Therefore, you should either include hidsdi.h before hidpi.h, or only include hidsdi.h. This still seems odd to me though, since the Windows documentation for the structure that I'm using (HIDP_PREPARSED_DATA) says that I only have to include hidpi.h; I wouldn't be surprised if this was a typo (wouldn't be the first time I've seen a typo in the Windows documentation).