TwiceAsNice  2019-02-18
Classes | Macros | Typedefs | Functions | Variables
hid_win.c File Reference
#include <windows.h>
#include <setupapi.h>
#include <winioctl.h>
#include <stdio.h>
#include <stdlib.h>
#include "hidapi.h"
Include dependency graph for hid_win.c:

Classes

struct  _HIDD_ATTRIBUTES
 
struct  _HIDP_CAPS
 
struct  hid_device_
 

Macros

#define HID_OUT_CTL_CODE(id)   CTL_CODE(FILE_DEVICE_KEYBOARD, (id), METHOD_OUT_DIRECT, FILE_ANY_ACCESS)
 
#define IOCTL_HID_GET_FEATURE   HID_OUT_CTL_CODE(100)
 
#define HIDP_STATUS_SUCCESS   0x110000
 
#define RESOLVE(x)
 
#define WSTR_LEN   512
 
#define P32
 

Typedefs

typedef LONG NTSTATUS
 
typedef struct _HIDD_ATTRIBUTES HIDD_ATTRIBUTES
 
typedef struct _HIDD_ATTRIBUTESPHIDD_ATTRIBUTES
 
typedef USHORT USAGE
 
typedef struct _HIDP_CAPS HIDP_CAPS
 
typedef struct _HIDP_CAPSPHIDP_CAPS
 
typedef void * PHIDP_PREPARSED_DATA
 
typedef BOOLEAN(__stdcall * HidD_GetAttributes_) (HANDLE device, PHIDD_ATTRIBUTES attrib)
 
typedef BOOLEAN(__stdcall * HidD_GetSerialNumberString_) (HANDLE device, PVOID buffer, ULONG buffer_len)
 
typedef BOOLEAN(__stdcall * HidD_GetManufacturerString_) (HANDLE handle, PVOID buffer, ULONG buffer_len)
 
typedef BOOLEAN(__stdcall * HidD_GetProductString_) (HANDLE handle, PVOID buffer, ULONG buffer_len)
 
typedef BOOLEAN(__stdcall * HidD_SetFeature_) (HANDLE handle, PVOID data, ULONG length)
 
typedef BOOLEAN(__stdcall * HidD_GetFeature_) (HANDLE handle, PVOID data, ULONG length)
 
typedef BOOLEAN(__stdcall * HidD_GetIndexedString_) (HANDLE handle, ULONG string_index, PVOID buffer, ULONG buffer_len)
 
typedef BOOLEAN(__stdcall * HidD_GetPreparsedData_) (HANDLE handle, PHIDP_PREPARSED_DATA *preparsed_data)
 
typedef BOOLEAN(__stdcall * HidD_FreePreparsedData_) (PHIDP_PREPARSED_DATA preparsed_data)
 
typedef NTSTATUS(__stdcall * HidP_GetCaps_) (PHIDP_PREPARSED_DATA preparsed_data, HIDP_CAPS *caps)
 

Functions

static hid_devicenew_hid_device ()
 
static void register_error (hid_device *device, const char *op)
 
static int lookup_functions ()
 
static HANDLE open_device (const char *path, BOOL enumerate)
 
int HID_API_EXPORT hid_init (void)
 Initialize the HIDAPI library. More...
 
int HID_API_EXPORT hid_exit (void)
 Finalize the HIDAPI library. More...
 
struct hid_device_info HID_API_EXPORT *HID_API_CALL hid_enumerate (unsigned short vendor_id, unsigned short product_id)
 Enumerate the HID Devices. More...
 
void HID_API_EXPORT HID_API_CALL hid_free_enumeration (struct hid_device_info *devs)
 Free an enumeration Linked List. More...
 
HID_API_EXPORT hid_device *HID_API_CALL hid_open (unsigned short vendor_id, unsigned short product_id, const wchar_t *serial_number)
 Open a HID device using a Vendor ID (VID), Product ID (PID) and optionally a serial number. More...
 
HID_API_EXPORT hid_device *HID_API_CALL hid_open_path (const char *path)
 Open a HID device by its path name. More...
 
int HID_API_EXPORT HID_API_CALL hid_write (hid_device *dev, const unsigned char *data, size_t length)
 Write an Output report to a HID device. More...
 
int HID_API_EXPORT HID_API_CALL hid_read_timeout (hid_device *dev, unsigned char *data, size_t length, int milliseconds)
 Read an Input report from a HID device with timeout. More...
 
int HID_API_EXPORT HID_API_CALL hid_read (hid_device *dev, unsigned char *data, size_t length)
 Read an Input report from a HID device. More...
 
int HID_API_EXPORT HID_API_CALL hid_set_nonblocking (hid_device *dev, int nonblock)
 Set the device handle to be non-blocking. More...
 
int HID_API_EXPORT HID_API_CALL hid_send_feature_report (hid_device *dev, const unsigned char *data, size_t length)
 Send a Feature report to the device. More...
 
int HID_API_EXPORT HID_API_CALL hid_get_feature_report (hid_device *dev, unsigned char *data, size_t length)
 Get a feature report from a HID device. More...
 
void HID_API_EXPORT HID_API_CALL hid_close (hid_device *dev)
 Close a HID device. More...
 
int HID_API_EXPORT_CALL HID_API_CALL hid_get_manufacturer_string (hid_device *dev, wchar_t *string, size_t maxlen)
 Get The Manufacturer String from a HID device. More...
 
int HID_API_EXPORT_CALL HID_API_CALL hid_get_product_string (hid_device *dev, wchar_t *string, size_t maxlen)
 Get The Product String from a HID device. More...
 
int HID_API_EXPORT_CALL HID_API_CALL hid_get_serial_number_string (hid_device *dev, wchar_t *string, size_t maxlen)
 Get The Serial Number String from a HID device. More...
 
int HID_API_EXPORT_CALL HID_API_CALL hid_get_indexed_string (hid_device *dev, int string_index, wchar_t *string, size_t maxlen)
 Get a string from a HID device, based on its string index. More...
 
HID_API_EXPORT const wchar_t *HID_API_CALL hid_error (hid_device *dev)
 Get a string describing the last error which occurred. More...
 

Variables

static HidD_GetAttributes_ HidD_GetAttributes
 
static HidD_GetSerialNumberString_ HidD_GetSerialNumberString
 
static HidD_GetManufacturerString_ HidD_GetManufacturerString
 
static HidD_GetProductString_ HidD_GetProductString
 
static HidD_SetFeature_ HidD_SetFeature
 
static HidD_GetFeature_ HidD_GetFeature
 
static HidD_GetIndexedString_ HidD_GetIndexedString
 
static HidD_GetPreparsedData_ HidD_GetPreparsedData
 
static HidD_FreePreparsedData_ HidD_FreePreparsedData
 
static HidP_GetCaps_ HidP_GetCaps
 
static HMODULE lib_handle = NULL
 
static BOOLEAN initialized = FALSE
 
unsigned short VendorID = 0x04d8
 
unsigned short ProductID = 0x3f
 

Macro Definition Documentation

◆ HID_OUT_CTL_CODE

#define HID_OUT_CTL_CODE (   id)    CTL_CODE(FILE_DEVICE_KEYBOARD, (id), METHOD_OUT_DIRECT, FILE_ANY_ACCESS)

◆ HIDP_STATUS_SUCCESS

#define HIDP_STATUS_SUCCESS   0x110000

◆ IOCTL_HID_GET_FEATURE

#define IOCTL_HID_GET_FEATURE   HID_OUT_CTL_CODE(100)

◆ P32

#define P32

◆ RESOLVE

#define RESOLVE (   x)
Value:
x = (x##_)GetProcAddress(lib_handle, #x); \
if (!x) \
return -1;
x
Definition: meteoRRD_updater.py:125
static HMODULE lib_handle
Definition: hid_win.c:128

◆ WSTR_LEN

#define WSTR_LEN   512

Typedef Documentation

◆ HIDD_ATTRIBUTES

◆ HidD_FreePreparsedData_

typedef BOOLEAN(__stdcall * HidD_FreePreparsedData_) (PHIDP_PREPARSED_DATA preparsed_data)

◆ HidD_GetAttributes_

typedef BOOLEAN(__stdcall * HidD_GetAttributes_) (HANDLE device, PHIDD_ATTRIBUTES attrib)

◆ HidD_GetFeature_

typedef BOOLEAN(__stdcall * HidD_GetFeature_) (HANDLE handle, PVOID data, ULONG length)

◆ HidD_GetIndexedString_

typedef BOOLEAN(__stdcall * HidD_GetIndexedString_) (HANDLE handle, ULONG string_index, PVOID buffer, ULONG buffer_len)

◆ HidD_GetManufacturerString_

typedef BOOLEAN(__stdcall * HidD_GetManufacturerString_) (HANDLE handle, PVOID buffer, ULONG buffer_len)

◆ HidD_GetPreparsedData_

typedef BOOLEAN(__stdcall * HidD_GetPreparsedData_) (HANDLE handle, PHIDP_PREPARSED_DATA *preparsed_data)

◆ HidD_GetProductString_

typedef BOOLEAN(__stdcall * HidD_GetProductString_) (HANDLE handle, PVOID buffer, ULONG buffer_len)

◆ HidD_GetSerialNumberString_

typedef BOOLEAN(__stdcall * HidD_GetSerialNumberString_) (HANDLE device, PVOID buffer, ULONG buffer_len)

◆ HidD_SetFeature_

typedef BOOLEAN(__stdcall * HidD_SetFeature_) (HANDLE handle, PVOID data, ULONG length)

◆ HIDP_CAPS

typedef struct _HIDP_CAPS HIDP_CAPS

◆ HidP_GetCaps_

typedef NTSTATUS(__stdcall * HidP_GetCaps_) (PHIDP_PREPARSED_DATA preparsed_data, HIDP_CAPS *caps)

◆ NTSTATUS

typedef LONG NTSTATUS

◆ PHIDD_ATTRIBUTES

◆ PHIDP_CAPS

typedef struct _HIDP_CAPS * PHIDP_CAPS

◆ PHIDP_PREPARSED_DATA

typedef void* PHIDP_PREPARSED_DATA

◆ USAGE

typedef USHORT USAGE

Function Documentation

◆ lookup_functions()

static int lookup_functions ( )
static

◆ new_hid_device()

static hid_device* new_hid_device ( void  )
static

◆ open_device()

static HANDLE open_device ( const char *  path,
BOOL  enumerate 
)
static

◆ register_error()

static void register_error ( hid_device device,
const char *  op 
)
static

Variable Documentation

◆ HidD_FreePreparsedData

HidD_FreePreparsedData_ HidD_FreePreparsedData
static

◆ HidD_GetAttributes

HidD_GetAttributes_ HidD_GetAttributes
static

◆ HidD_GetFeature

HidD_GetFeature_ HidD_GetFeature
static

◆ HidD_GetIndexedString

HidD_GetIndexedString_ HidD_GetIndexedString
static

◆ HidD_GetManufacturerString

HidD_GetManufacturerString_ HidD_GetManufacturerString
static

◆ HidD_GetPreparsedData

HidD_GetPreparsedData_ HidD_GetPreparsedData
static

◆ HidD_GetProductString

HidD_GetProductString_ HidD_GetProductString
static

◆ HidD_GetSerialNumberString

HidD_GetSerialNumberString_ HidD_GetSerialNumberString
static

◆ HidD_SetFeature

HidD_SetFeature_ HidD_SetFeature
static

◆ HidP_GetCaps

HidP_GetCaps_ HidP_GetCaps
static

◆ initialized

BOOLEAN initialized = FALSE
static

◆ lib_handle

HMODULE lib_handle = NULL
static

◆ ProductID

unsigned short ProductID = 0x3f

◆ VendorID

unsigned short VendorID = 0x04d8