SDL  2.0
SDL_hid.c
Go to the documentation of this file.
1 /*
2  Simple DirectMedia Layer
3  Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
4 
5  This software is provided 'as-is', without any express or implied
6  warranty. In no event will the authors be held liable for any damages
7  arising from the use of this software.
8 
9  Permission is granted to anyone to use this software for any purpose,
10  including commercial applications, and to alter it and redistribute it
11  freely, subject to the following restrictions:
12 
13  1. The origin of this software must not be misrepresented; you must not
14  claim that you wrote the original software. If you use this software
15  in a product, an acknowledgment in the product documentation would be
16  appreciated but is not required.
17  2. Altered source versions must be plainly marked as such, and must not be
18  misrepresented as being the original software.
19  3. This notice may not be removed or altered from any source distribution.
20 */
21 #include "../../SDL_internal.h"
22 
23 #ifndef __WINRT__
24 
25 #include "SDL_hid.h"
26 
27 
37 
38 static HMODULE s_pHIDDLL = 0;
39 static int s_HIDDLLRefCount = 0;
40 
41 
42 int
44 {
45  if (s_pHIDDLL) {
48  return 0; /* already loaded */
49  }
50 
51  s_pHIDDLL = LoadLibrary(L"hid.dll");
52  if (!s_pHIDDLL) {
53  return -1;
54  }
55 
57  s_HIDDLLRefCount = 1;
58 
59  SDL_HidD_GetManufacturerString = (HidD_GetString_t)GetProcAddress(s_pHIDDLL, "HidD_GetManufacturerString");
60  SDL_HidD_GetProductString = (HidD_GetString_t)GetProcAddress(s_pHIDDLL, "HidD_GetProductString");
61  SDL_HidD_GetPreparsedData = (HidD_GetPreparsedData_t)GetProcAddress(s_pHIDDLL, "HidD_GetPreparsedData");
62  SDL_HidD_FreePreparsedData = (HidD_FreePreparsedData_t)GetProcAddress(s_pHIDDLL, "HidD_FreePreparsedData");
63  SDL_HidP_GetCaps = (HidP_GetCaps_t)GetProcAddress(s_pHIDDLL, "HidP_GetCaps");
64  SDL_HidP_GetButtonCaps = (HidP_GetButtonCaps_t)GetProcAddress(s_pHIDDLL, "HidP_GetButtonCaps");
65  SDL_HidP_GetValueCaps = (HidP_GetValueCaps_t)GetProcAddress(s_pHIDDLL, "HidP_GetValueCaps");
66  SDL_HidP_MaxDataListLength = (HidP_MaxDataListLength_t)GetProcAddress(s_pHIDDLL, "HidP_MaxDataListLength");
67  SDL_HidP_GetData = (HidP_GetData_t)GetProcAddress(s_pHIDDLL, "HidP_GetData");
72  return -1;
73  }
74 
75  return 0;
76 }
77 
78 void
80 {
81  if (s_pHIDDLL) {
83  if (--s_HIDDLLRefCount == 0) {
84  FreeLibrary(s_pHIDDLL);
85  s_pHIDDLL = NULL;
86  }
87  } else {
89  }
90 }
91 
92 #endif /* !__WINRT__ */
93 
94 /* vi: set ts=4 sw=4 expandtab: */
#define SDL_assert(condition)
Definition: SDL_assert.h:171
HidD_FreePreparsedData_t SDL_HidD_FreePreparsedData
Definition: SDL_hid.c:31
HidP_GetCaps_t SDL_HidP_GetCaps
Definition: SDL_hid.c:32
HidP_GetButtonCaps_t SDL_HidP_GetButtonCaps
Definition: SDL_hid.c:33
HidD_GetString_t SDL_HidD_GetManufacturerString
Definition: SDL_hid.c:28
HidD_GetPreparsedData_t SDL_HidD_GetPreparsedData
Definition: SDL_hid.c:30
void WIN_UnloadHIDDLL(void)
Definition: SDL_hid.c:79
static HMODULE s_pHIDDLL
Definition: SDL_hid.c:38
HidP_MaxDataListLength_t SDL_HidP_MaxDataListLength
Definition: SDL_hid.c:35
HidP_GetValueCaps_t SDL_HidP_GetValueCaps
Definition: SDL_hid.c:34
static int s_HIDDLLRefCount
Definition: SDL_hid.c:39
HidP_GetData_t SDL_HidP_GetData
Definition: SDL_hid.c:36
int WIN_LoadHIDDLL(void)
Definition: SDL_hid.c:43
HidD_GetString_t SDL_HidD_GetProductString
Definition: SDL_hid.c:29
BOOLEAN(WINAPI * HidD_GetString_t)(HANDLE HidDeviceObject, PVOID Buffer, ULONG BufferLength)
Definition: SDL_hid.h:185
NTSTATUS(WINAPI * HidP_GetValueCaps_t)(HIDP_REPORT_TYPE ReportType, PHIDP_VALUE_CAPS ValueCaps, PUSHORT ValueCapsLength, PHIDP_PREPARSED_DATA PreparsedData)
Definition: SDL_hid.h:190
NTSTATUS(WINAPI * HidP_GetCaps_t)(PHIDP_PREPARSED_DATA PreparsedData, PHIDP_CAPS Capabilities)
Definition: SDL_hid.h:188
BOOLEAN(WINAPI * HidD_GetPreparsedData_t)(HANDLE HidDeviceObject, PHIDP_PREPARSED_DATA *PreparsedData)
Definition: SDL_hid.h:186
NTSTATUS(WINAPI * HidP_GetData_t)(HIDP_REPORT_TYPE ReportType, PHIDP_DATA DataList, PULONG DataLength, PHIDP_PREPARSED_DATA PreparsedData, PCHAR Report, ULONG ReportLength)
Definition: SDL_hid.h:192
BOOLEAN(WINAPI * HidD_FreePreparsedData_t)(PHIDP_PREPARSED_DATA PreparsedData)
Definition: SDL_hid.h:187
NTSTATUS(WINAPI * HidP_GetButtonCaps_t)(HIDP_REPORT_TYPE ReportType, PHIDP_BUTTON_CAPS ButtonCaps, PUSHORT ButtonCapsLength, PHIDP_PREPARSED_DATA PreparsedData)
Definition: SDL_hid.h:189
ULONG(WINAPI * HidP_MaxDataListLength_t)(HIDP_REPORT_TYPE ReportType, PHIDP_PREPARSED_DATA PreparsedData)
Definition: SDL_hid.h:191
#define NULL
Definition: begin_code.h:163