Source file: /~heha/hsn/bl/hid-flash.zip/src/hidapi.h

/*
 HIDAPI - Multi-Platform library for communication with HID devices.
 8/22/2009	Alan Ott, Signal 11 Software
*/

#pragma once
#ifdef _WIN32
#include <windows.h>
typedef DWORD uint32_t;
extern "C"{
#include <hidsdi.h>	//HIDD_ATTRIBUTES,HIDP_CAPS
}
#else
#include <stdint.h>
#define INFINITE 0
#define LOWORD(x) (uint16_t)(x)
#define HIWORD(x) (uint16_t)((x)>>16)
namespace hid{
struct Attr{
 uint16_t VendorID,ProductID,VersionNumber;
};
struct Caps {
// uint16_t Usage,UsagePage;
 int	InputReportByteLength,
	OutputReportByteLength,
	FeatureReportByteLength;
};
}
//#include <libusb-1.0/libusb.h>
#endif

typedef unsigned char byte;
#define elemof(x) (sizeof(x)/sizeof(*(x)))

class HidDev {
 virtual bool match() const =0;
 virtual void retry_msg() const =0;
 char*readbuf;
#if __cplusplus >= 201100L
 HidDev&operator=(const HidDev&o) = delete;	// No copy operator
 HidDev(const HidDev&o) = delete;		// No copy constructor
#endif
public:
 struct RetStr{		// As a big struct, space is caller-reserved on stack ...
#ifdef WIN32
  wchar_t s[128];	// and address is passed as hidden __$ReturnUdt parameter
#else
  char s[256];
#endif
 };
 HidDev();
 virtual ~HidDev();
 bool connect(unsigned n=0);
// Timeout values are for each attempt.
// Overall time depends on retry_msg delay which should wait 100 ms.
 bool setOutputReport(const byte*data, unsigned attempts=5, unsigned ms_each=INFINITE);
 bool getInputReport(byte*data, unsigned attempts=5, unsigned ms_each=INFINITE);
 bool setFeatureReport(const byte*data, unsigned attempts=5);
 bool getFeatureReport(byte*data, unsigned attempts=5);
 RetStr getIndexedStr(byte index) const;
 RetStr getManufacturerStr() const;
 RetStr getProductStr() const;
 RetStr getSerialStr() const;
 uint32_t vidpid() const;	// HIWORD = PID, LOWORD = VID, from attr
 operator bool() const {return !!handle;}
 unsigned short VersionNumber() const {return attr.VersionNumber;}
private:
#ifdef WIN32
 HANDLE handle;
public:
 HIDD_ATTRIBUTES attr;
 HIDP_CAPS caps;
#else
 int handle;
public:
 hid::Attr attr;
 hid::Caps caps;
#endif
};
Detected encoding: ASCII (7 bit)2