1

I am trying to use the tagRAWINPUTDEVICE struct from WinUser.h.

(Edited) Here is all of my code:

#define WINVER 0x0A00
#define _WIN32_WINNT 0x0A00

#include <Windows.h>

int main()
{
    RAWINPUTDEVICE rid[1];
    return 0;
}

I compile the code with:

g++ test.cpp

I get this error:

test.cpp: In function `int main()':
test.cpp:8: `RAWINPUTDEVICE' undeclared (first use this function)
test.cpp:8: (Each undeclared identifier is reported only once
test.cpp:8: for each function it appears in.)
test.cpp:8: parse error before `['

Here is the struct from WinUser.h:

typedef struct tagRAWINPUTDEVICE {
    USHORT usUsagePage; // Toplevel collection UsagePage
    USHORT usUsage;     // Toplevel collection Usage
    DWORD dwFlags;
    HWND hwndTarget;    // Target hwnd. NULL = follows keyboard focus
} RAWINPUTDEVICE, *PRAWINPUTDEVICE, *LPRAWINPUTDEVICE;

I don't see any other requirements in the documentation, so I don't see why there is an error.

Jabberwocky
  • 48,281
  • 17
  • 65
  • 115
wwwwwwww
  • 33
  • 4
  • 5
    I'm not familiar with programming on Windows, but the header requirements in that documentation says *winuser.h (include Windows.h)*. Does that mean you should include `Windows.h` instead of `winuser.h` directly? – Kevin Nov 26 '18 at 19:47
  • 4
    See [Using the Windows Headers](https://learn.microsoft.com/en-us/windows/desktop/winprog/using-the-windows-headers) including the discussion on the versioning macros you need to define. Raw Input requires `_WIN32_WINNT` to be at least `0x0501`. – Jonathan Potter Nov 26 '18 at 19:57
  • I tried both suggestions, but the error remained unchanged, although I'm not sure if my changes were correct. I edited my post with more detail. – wwwwwwww Nov 26 '18 at 20:29
  • You need to define the target version *before* including the headers. You typically define it on the command line. – IInspectable Nov 26 '18 at 20:31
  • Alright, I changed the order, but I get the same error. Is my syntax still incorrect, or is the problem somewhere else? – wwwwwwww Nov 26 '18 at 20:47
  • @Kevin That is exactly what it means. – Remy Lebeau Nov 26 '18 at 22:19
  • 1
    @JonathanPotter `0x0A00` (2560) is `> 0x0501` (1281). – Remy Lebeau Nov 26 '18 at 22:20
  • 1
    @wwwwwwww is it possible that your project is using a pre-compiled header that you did not show here? If so, your `#include` statement would have no effect if that header has already been included previously, before your `#define` statements, so `windows.h` (and thus `winuser.h`) would be using pre-defined values for `WINVER` and `_WIN32_WINNT` that may be too low for your needs. Also see [Modifying WINVER and _WIN32_WINNT](https://learn.microsoft.com/en-us/cpp/porting/modifying-winver-and-win32-winnt) – Remy Lebeau Nov 26 '18 at 22:23
  • @RemyLebeau that code wasn't in there when I posted my comment – Jonathan Potter Nov 26 '18 at 22:37
  • @RemyLebeau Everything in my `test.cpp` file is posted above. I don't think its using a pre-compiled header, although I'm not certain since I never worked with pre-compiled headers. – wwwwwwww Nov 26 '18 at 23:17
  • @wwwwwwww which compiler/toolchain are you using exactly? – Remy Lebeau Nov 27 '18 at 01:29
  • 1
    Compiles perfect with VS 15.9.2. The problem is not in the code but in the build environment. – Werner Henze Nov 27 '18 at 08:17
  • `0x0A00` is not a (currently) supported value to use for `_WIN32_WINNT` or `WINVER`. If you properly set those preprocessor symbols, and the build still fails, then you probably use a very old Windows SDK. The Windows SDK is, for all practical purposes, backward compatible. You should always install the latest version of the SDK, and control your target platform through the preprocessor symbols mentioned above. – IInspectable Nov 27 '18 at 10:56
  • @IInspectable I tried to define `WINVER` and `_WIN32_WINNT` as `0x0501`, but I get the same error. I believe I already have the latest version of the Windows SDK, but now I'm not sure; where do I look for the latest version? – wwwwwwww Nov 27 '18 at 15:18
  • @RemyLebeau I am using `g++` to compile my code. – wwwwwwww Nov 27 '18 at 15:20
  • Apparently, using VS 2017 works. Guess I'll just use that now... – wwwwwwww Nov 27 '18 at 16:17
  • Have GCC show the includes (see this [Q&A](https://stackoverflow.com/q/4479049/1889329)). That'll tell you which version of the SDK it is using. – IInspectable Nov 27 '18 at 20:10

0 Answers0