22 typedef USHORT USAGE, *PUSAGE;
29 typedef enum _HIDP_REPORT_TYPE
36 typedef struct _HIDP_CAPS
40 USHORT InputReportByteLength;
41 USHORT OutputReportByteLength;
42 USHORT FeatureReportByteLength;
45 USHORT NumberLinkCollectionNodes;
47 USHORT NumberInputButtonCaps;
48 USHORT NumberInputValueCaps;
49 USHORT NumberInputDataIndices;
51 USHORT NumberOutputButtonCaps;
52 USHORT NumberOutputValueCaps;
53 USHORT NumberOutputDataIndices;
55 USHORT NumberFeatureButtonCaps;
56 USHORT NumberFeatureValueCaps;
57 USHORT NumberFeatureDataIndices;
58 } HIDP_CAPS, *PHIDP_CAPS;
60 typedef struct _HIDP_LINK_COLLECTION_NODE
65 USHORT NumberOfChildren;
68 ULONG CollectionType: 8;
72 } HIDP_LINK_COLLECTION_NODE, *PHIDP_LINK_COLLECTION_NODE;
74 typedef struct _HIDP_BUTTON_CAPS
81 USHORT LinkCollection;
87 BOOLEAN IsStringRange;
88 BOOLEAN IsDesignatorRange;
94 USAGE UsageMin, UsageMax;
95 USHORT StringMin, StringMax;
96 USHORT DesignatorMin, DesignatorMax;
97 USHORT DataIndexMin, DataIndexMax;
100 USAGE Usage, Reserved1;
101 USHORT StringIndex, Reserved2;
102 USHORT DesignatorIndex, Reserved3;
103 USHORT DataIndex, Reserved4;
107 } HIDP_BUTTON_CAPS, *PHIDP_BUTTON_CAPS;
109 typedef struct _HIDP_VALUE_CAPS
116 USHORT LinkCollection;
122 BOOLEAN IsStringRange;
123 BOOLEAN IsDesignatorRange;
136 LONG LogicalMin, LogicalMax;
137 LONG PhysicalMin, PhysicalMax;
141 USAGE UsageMin, UsageMax;
142 USHORT StringMin, StringMax;
143 USHORT DesignatorMin, DesignatorMax;
144 USHORT DataIndexMin, DataIndexMax;
148 USAGE Usage, Reserved1;
149 USHORT StringIndex, Reserved2;
150 USHORT DesignatorIndex, Reserved3;
151 USHORT DataIndex, Reserved4;
154 } HIDP_VALUE_CAPS, *PHIDP_VALUE_CAPS;
156 typedef PUCHAR PHIDP_REPORT_DESCRIPTOR;
157 typedef struct _HIDP_PREPARSED_DATA * PHIDP_PREPARSED_DATA;
158 #ifndef FACILITY_HID_ERROR_CODE
159 #define FACILITY_HID_ERROR_CODE 0x11
161 #define HIDP_ERROR_CODES(SEV, CODE) \
162 ((NTSTATUS) (((SEV) << 28) | (FACILITY_HID_ERROR_CODE << 16) | (CODE)))
163 #define HIDP_STATUS_SUCCESS (HIDP_ERROR_CODES(0x0,0))
170 typedef struct _HIDD_ATTRIBUTES
176 USHORT VersionNumber;
178 } HIDD_ATTRIBUTES, *PHIDD_ATTRIBUTES;
179 typedef LONG NTSTATUS;
231 if ( m_module != NULL )
233 ::FreeLibrary(m_module);
258 BOOLEAN (__stdcall *P)(HANDLE hidDeviceObject, PHIDD_ATTRIBUTES pAttributes) = 0;
259 return Func(P,
"HidD_GetAttributes")(hidDeviceObject, pAttributes);
272 BOOLEAN (__stdcall *P)(HANDLE hidDeviceObject, PHIDP_PREPARSED_DATA* ppPreparsedData) = 0;
273 return Func(P,
"HidD_GetPreparsedData")(hidDeviceObject, ppPreparsedData);
285 BOOLEAN (__stdcall *P)(PHIDP_PREPARSED_DATA pPreparsedData) = 0;
286 return Func(P,
"HidD_FreePreparsedData")(pPreparsedData);
297 BOOLEAN
HidD_SetFeature(HANDLE hidDeviceObject,PVOID pReportBuffer, ULONG reportBufferLength)
299 BOOLEAN (__stdcall *P)(HANDLE hidDeviceObject,PVOID pReportBuffer, ULONG reportBufferLength) = 0;
300 return Func(P,
"HidD_SetFeature")(hidDeviceObject, pReportBuffer, reportBufferLength);
311 BOOLEAN
HidD_GetFeature(HANDLE hidDeviceObject, PVOID pReportBuffer, ULONG reportBufferLength)
const
313 BOOLEAN (__stdcall *P)(HANDLE hidDeviceObject, PVOID pReportBuffer, ULONG reportBufferLength) = 0;
314 return Func(P,
"HidD_GetFeature")(hidDeviceObject, pReportBuffer, reportBufferLength);
327 BOOLEAN (__stdcall *P)(HANDLE hidDeviceObject, PVOID pReportBuffer, ULONG reportBufferLength) = 0;
328 return Func(P,
"HidD_SetOutputReport")(hidDeviceObject, pReportBuffer, reportBufferLength);
341 BOOLEAN (__stdcall *P)(HANDLE hidDeviceObject, PVOID pReportBuffer, ULONG reportBufferLength) = 0;
342 return Func(P,
"HidD_GetInputReport")(hidDeviceObject, pReportBuffer, reportBufferLength);
351 void (__stdcall *P)(LPGUID pHidGuid) = NULL;
352 Func(P,
"HidD_GetHidGuid")(pHidGuid);
365 BOOLEAN (__stdcall *P)(HANDLE hidDeviceObject, PVOID pBuffer, ULONG bufferLength) = 0;
366 return Func(P,
"HidD_GetManufacturerString")(hidDeviceObject, pBuffer, bufferLength);
379 BOOLEAN (__stdcall *P)(HANDLE hidDeviceObject, PVOID pBuffer, ULONG bufferLength) = 0;
380 return Func(P,
"HidD_GetProductString")(hidDeviceObject, pBuffer, bufferLength);
393 BOOLEAN (__stdcall *P)(HANDLE hidDeviceObject, PVOID pBuffer, ULONG bufferLength) = 0;
394 return Func(P,
"HidD_GetSerialNumberString")(hidDeviceObject, pBuffer, bufferLength);
408 BOOLEAN (__stdcall *P)(HANDLE hidDeviceObject, ULONG stringIndex, PVOID pBuffer, ULONG bufferLength) = 0;
409 return Func(P,
"HidD_GetIndexedString")(hidDeviceObject, stringIndex, pBuffer, bufferLength);
421 BOOLEAN (__stdcall *P)(HANDLE hidDeviceObject, PULONG pNumberBuffers) = 0;
422 return Func(P,
"HidD_GetNumInputBuffers")(hidDeviceObject, pNumberBuffers);
434 BOOLEAN (__stdcall *P)(HANDLE hidDeviceObject, ULONG numberBuffers) = 0;
435 return Func(P,
"HidD_SetNumInputBuffers")(hidDeviceObject, numberBuffers);
446 BOOLEAN (__stdcall *P)(HANDLE hidDeviceObject) = 0;
447 return Func(P,
"HidD_FlushQueue")(hidDeviceObject);
457 NTSTATUS
HidP_GetCaps(PHIDP_PREPARSED_DATA pPreparsedData, PHIDP_CAPS pCapabilities)
const
459 NTSTATUS (__stdcall *P)(PHIDP_PREPARSED_DATA pPreparsedData, PHIDP_CAPS pCapabilities) = 0;
460 return Func(P,
"HidP_GetCaps")(pPreparsedData, pCapabilities);
471 NTSTATUS
HidP_GetLinkCollectionNodes(PHIDP_LINK_COLLECTION_NODE pLinkCollectionNodes, PULONG pLinkCollectionNodesLength, PHIDP_PREPARSED_DATA pPreparsedData)
473 NTSTATUS (__stdcall *P)(PHIDP_LINK_COLLECTION_NODE pLinkCollectionNodes, PULONG pLinkCollectionNodesLength, PHIDP_PREPARSED_DATA pPreparsedData) = 0;
474 return Func(P,
"HidP_GetLinkCollectionNodes")(pLinkCollectionNodes, pLinkCollectionNodesLength, pPreparsedData);
489 NTSTATUS
HidP_GetSpecificButtonCaps(HIDP_REPORT_TYPE reportType, USAGE usagePage, USHORT linkCollection, USAGE usage, PHIDP_BUTTON_CAPS pButtonCaps, PUSHORT pButtonCapsLength, PHIDP_PREPARSED_DATA pPreparsedData)
491 NTSTATUS (__stdcall *P)(HIDP_REPORT_TYPE reportType, USAGE usagePage, USHORT linkCollection, USAGE usage, PHIDP_BUTTON_CAPS pButtonCaps, PUSHORT pButtonCapsLength, PHIDP_PREPARSED_DATA pPreparsedData) = 0;
492 return Func(P,
"HidP_GetSpecificButtonCaps")(reportType, usagePage, linkCollection, usage, pButtonCaps, pButtonCapsLength, pPreparsedData);
504 NTSTATUS
HidP_GetButtonCaps(HIDP_REPORT_TYPE reportType, PHIDP_BUTTON_CAPS pButtonCaps, PUSHORT pButtonCapsLength, PHIDP_PREPARSED_DATA pPreparsedData)
521 NTSTATUS
HidP_GetSpecificValueCaps(HIDP_REPORT_TYPE reportType, USAGE usagePage, USHORT linkCollection, USAGE usage, PHIDP_VALUE_CAPS pValueCaps, PUSHORT pValueCapsLength, PHIDP_PREPARSED_DATA pPreparsedData)
523 NTSTATUS (__stdcall *P)(HIDP_REPORT_TYPE reportType, USAGE usagePage, USHORT linkCollection, USAGE usage, PHIDP_VALUE_CAPS pValueCaps, PUSHORT pValueCapsLength, PHIDP_PREPARSED_DATA pPreparsedData) = 0;
524 return Func(P,
"HidP_GetSpecificValueCaps")(reportType, usagePage, linkCollection, usage, pValueCaps, pValueCapsLength, pPreparsedData);
536 NTSTATUS
HidP_GetValueCaps(HIDP_REPORT_TYPE reportType, PHIDP_VALUE_CAPS pValueCaps, PUSHORT pValueCapsLength, PHIDP_PREPARSED_DATA pPreparsedData)
544 template<
typename TYP>
545 TYP Func(TYP typ, LPCSTR lpsz)
const
547 if ( m_module == NULL )
549 m_module = ::LoadLibrary(_T(
"hid.dll"));
550 ASSERT( m_module != NULL );
552 ForceSet(typ, ::GetProcAddress(m_module, lpsz));
553 ASSERT1( typ != NULL,
"CUsbHidApi::Func",
"[%s]が見つかりませんでした", lpsz );
557 mutable HMODULE m_module;
606 : m_vendorId(wVid), m_productId(wPid), m_pathName(lpszPathName), m_hidpCaps(cap)
630 m_regPathHid.
Empty();
631 m_regPathUsb.
Empty();
647 DWORD shareMode = (FILE_SHARE_READ | FILE_SHARE_WRITE);
648 HANDLE h = ::CreateFile(lpszPathName, GENERIC_WRITE, shareMode, NULL, OPEN_EXISTING, 0, 0);
649 if ( h == INVALID_HANDLE_VALUE )
651 return _GetLastError(
"CreateFile");
653 DWORD dwResult = ERROR_SUCCESS;
654 HIDD_ATTRIBUTES attr;
655 attr.Size =
sizeof(HIDD_ATTRIBUTES);
659 dwResult = _GetLastError(
"HidD_GetAttributes");
663 PHIDP_PREPARSED_DATA pPreparsedData;
666 dwResult = _GetLastError(
"HidD_GetPreparsedData");
672 m_vendorId = attr.VendorID;
673 m_productId = attr.ProductID;
674 m_pathName = lpszPathName;
675 m_regPathHid.
Empty();
676 m_regPathUsb.
Empty();
692 _vn.
Resize(m_hidpCaps.NumberLinkCollectionNodes);
693 DWORD shareMode = (FILE_SHARE_READ | FILE_SHARE_WRITE);
694 HANDLE h = ::CreateFile(m_pathName, GENERIC_WRITE, shareMode, NULL, OPEN_EXISTING, 0, 0);
695 if ( h == INVALID_HANDLE_VALUE )
697 _GetLastError(
"CreateFile");
701 PHIDP_PREPARSED_DATA pPreparsedData;
704 ULONG ul =
static_cast<ULONG
>(_vn.
GetSize());
721 switch ( reportType )
724 _vn.
Resize(m_hidpCaps.NumberInputButtonCaps);
727 _vn.
Resize(m_hidpCaps.NumberOutputButtonCaps);
731 _vn.
Resize(m_hidpCaps.NumberFeatureButtonCaps);
734 DWORD shareMode = (FILE_SHARE_READ | FILE_SHARE_WRITE);
735 HANDLE h = ::CreateFile(m_pathName, GENERIC_WRITE, shareMode, NULL, OPEN_EXISTING, 0, 0);
736 if ( h == INVALID_HANDLE_VALUE )
738 _GetLastError(
"CreateFile");
742 PHIDP_PREPARSED_DATA pPreparsedData;
745 USHORT ul =
static_cast<USHORT
>(_vn.
GetSize());
762 switch ( reportType )
765 _vn.
Resize(m_hidpCaps.NumberInputValueCaps);
768 _vn.
Resize(m_hidpCaps.NumberOutputValueCaps);
772 _vn.
Resize(m_hidpCaps.NumberFeatureValueCaps);
775 DWORD shareMode = (FILE_SHARE_READ | FILE_SHARE_WRITE);
776 HANDLE h = ::CreateFile(m_pathName, GENERIC_WRITE, shareMode, NULL, OPEN_EXISTING, 0, 0);
777 if ( h == INVALID_HANDLE_VALUE )
779 _GetLastError(
"CreateFile");
783 PHIDP_PREPARSED_DATA pPreparsedData;
786 USHORT ul =
static_cast<USHORT
>(_vn.
GetSize());
836 return m_hidpCaps.InputReportByteLength;
845 return m_hidpCaps.OutputReportByteLength;
854 return m_hidpCaps.FeatureReportByteLength;
865 if ( ! m_regPathHid.
IsEmpty() )
868 return m_GetRegString(reg, m_regPathHid, _T(
"Mfg"));
881 if ( ! m_regPathHid.
IsEmpty() )
884 return m_GetRegString(reg, m_regPathHid, _T(
"DeviceDesc"));
897 if ( ! m_regPathUsb.
IsEmpty() )
900 return m_GetRegString(reg, m_regPathUsb, _T(
"LocationInformation"));
925 HANDLE hDown = ::CreateFile(m_pathName, GENERIC_WRITE, (FILE_SHARE_READ | FILE_SHARE_WRITE), NULL, OPEN_EXISTING, 0, 0);
926 if ( hDown == INVALID_HANDLE_VALUE )
949 ::CloseHandle(hDown);
1008 bool m_SearchRegPath(
void)
const
1012 INDEX f1 = m_pathName.
Find(
'#');
1013 INDEX f2 = m_pathName.
Find(
'#', f1 + 1);
1014 INDEX f3 = m_pathName.
Find(
'#', f2 + 1);
1015 if ( f1 != INVALID_INDEX && f2 != INVALID_INDEX && f3 != INVALID_INDEX )
1018 CStr vpid = m_pathName.
Mid(f1 + 1, f2 - f1 - 1);
1020 INDEX f = vpid.
Find(
'&', 18);
1021 if ( f != INVALID_INDEX )
1023 vpid2 = vpid.
Left(f);
1025 CStr key = m_pathName.
Mid(f2 + 1, f3 - f2 - 1);
1028 ff.Execute(reg[_T(
"USB\\") + vpid2]);
1029 m_regPathUsb = ff.m_foundPath;
1030 CStrVector vs = reg.EnumSectionNames(_T(
"HID\\") + vpid);
1033 m_regPathHid.
Format(_T(
"HID\\%s\\%s"), vpid, vs[0]);
1042 CStr s = reg[lpszSection].QueryString(lpszKey).Trim();
1043 INDEX f = s.
Find(
';');
1044 if ( f != INVALID_INDEX )
1051 LPCTSTR m_GetBaseRegPath(
void)
const
1053 return _T(
"System\\currentControlSet\\Enum");
1058 HIDP_CAPS m_hidpCaps;
1059 mutable CStr m_regPathHid;
1060 mutable CStr m_regPathUsb;
bool IsEmpty(void) const
[確認] 空チェック
CStrT Left(size_t iSize) const
[作成] 範囲取得.
void ReleaseBuffer(void)
[操作] 割り当てたバッファを開放.
size_t GetLength(void) const
[取得] 文字列長
INT_PTR Find(TYP t, INDEX iFromIndex=0) const
[確認] 検索.
bool IsEqual(const TYP *lpszSubject) const
[確認] 文字列比較
void Format(const TYP *lpszFormat,...)
[代入] 書式付き文字列代入.
CStrT Mid(INDEX iOffset, size_t iSize=INVALID_SIZE) const
[作成] 範囲取得.
TYP * GetBuffer(size_t iLength=0)
[操作] 書き込みバッファ要求.
NTSTATUS HidP_GetButtonCaps(HIDP_REPORT_TYPE reportType, PHIDP_BUTTON_CAPS pButtonCaps, PUSHORT pButtonCapsLength, PHIDP_PREPARSED_DATA pPreparsedData)
[取得] ボタン性能取得.
NTSTATUS HidP_GetLinkCollectionNodes(PHIDP_LINK_COLLECTION_NODE pLinkCollectionNodes, PULONG pLinkCollectionNodesLength, PHIDP_PREPARSED_DATA pPreparsedData)
[取得] リンクコレクションノード取得.
BOOLEAN HidD_SetFeature(HANDLE hidDeviceObject, PVOID pReportBuffer, ULONG reportBufferLength)
[送信] 機能レポート送信
BOOLEAN HidD_GetAttributes(HANDLE hidDeviceObject, PHIDD_ATTRIBUTES pAttributes) const
[取得] 属性取得.
CUsbHidApi & operator=(const CUsbHidApi &other)
コピーオペレータ
BOOLEAN HidD_SetNumInputBuffers(HANDLE hidDeviceObject, ULONG numberBuffers)
[設定] 入力バッファ数設定.
BOOLEAN HidD_GetFeature(HANDLE hidDeviceObject, PVOID pReportBuffer, ULONG reportBufferLength) const
[受信] 機能レポート受信
BOOLEAN HidD_GetNumInputBuffers(HANDLE hidDeviceObject, PULONG pNumberBuffers) const
[取得] 入力バッファ数取得.
BOOLEAN HidD_SetOutputReport(HANDLE hidDeviceObject, PVOID pReportBuffer, ULONG reportBufferLength)
[送信] Outputレポート送信
NTSTATUS HidP_GetSpecificButtonCaps(HIDP_REPORT_TYPE reportType, USAGE usagePage, USHORT linkCollection, USAGE usage, PHIDP_BUTTON_CAPS pButtonCaps, PUSHORT pButtonCapsLength, PHIDP_PREPARSED_DATA pPreparsedData)
[取得] ボタン詳細性能取得.
NTSTATUS HidP_GetSpecificValueCaps(HIDP_REPORT_TYPE reportType, USAGE usagePage, USHORT linkCollection, USAGE usage, PHIDP_VALUE_CAPS pValueCaps, PUSHORT pValueCapsLength, PHIDP_PREPARSED_DATA pPreparsedData)
[取得] 値詳細性能取得.
void HidD_GetHidGuid(LPGUID pHidGuid) const
[取得] HID GUID 取得.
BOOLEAN HidD_GetProductString(HANDLE hidDeviceObject, PVOID pBuffer, ULONG bufferLength) const
[取得] Product 文字列取得
CUsbHidApi(const CUsbHidApi &other)
コピーコンストラクタ.
NTSTATUS HidP_GetCaps(PHIDP_PREPARSED_DATA pPreparsedData, PHIDP_CAPS pCapabilities) const
[取得] 能力取得.
BOOLEAN HidD_GetInputReport(HANDLE hidDeviceObject, PVOID pReportBuffer, ULONG reportBufferLength) const
[受信] Inputレポート受信
BOOLEAN HidD_GetManufacturerString(HANDLE hidDeviceObject, PVOID pBuffer, ULONG bufferLength) const
[取得] Manufacturer 文字列取得
BOOLEAN HidD_GetPreparsedData(HANDLE hidDeviceObject, PHIDP_PREPARSED_DATA *ppPreparsedData) const
[取得] PREPARSEDデータ取得.
BOOLEAN HidD_FlushQueue(HANDLE hidDeviceObject)
[処理] キューフラッシュ.
BOOLEAN HidD_GetIndexedString(HANDLE hidDeviceObject, ULONG stringIndex, PVOID pBuffer, ULONG bufferLength) const
[取得] INDEXED 文字列取得
BOOLEAN HidD_GetSerialNumberString(HANDLE hidDeviceObject, PVOID pBuffer, ULONG bufferLength) const
[取得] SerialNumber 文字列取得
NTSTATUS HidP_GetValueCaps(HIDP_REPORT_TYPE reportType, PHIDP_VALUE_CAPS pValueCaps, PUSHORT pValueCapsLength, PHIDP_PREPARSED_DATA pPreparsedData)
[取得] 値性能取得.
BOOLEAN HidD_FreePreparsedData(PHIDP_PREPARSED_DATA pPreparsedData) const
[開放] PREPARSEDデータ開放.
CStr GetManufacturer(void) const
[取得] 製造業者取得.
CUsbHidPathName(WORD wVid, WORD wPid, LPCTSTR lpszPathName, const HIDP_CAPS &cap)
コンストラクタ
size_t GetOutputReportByteLength(void) const
[取得] Outputレポート長取得
CStr GetDeviceDescription(void) const
[取得] 説明取得.
bool IsEmpty(void) const
[確認] 情報有無確認
const HIDP_CAPS & GetCapability(void) const
[取得] Capability情報取得
bool GetLinkCollectionNodes(CWorkMemT< HIDP_LINK_COLLECTION_NODE > &_vn)
[設定] リンクコレクションノード情報取得.
bool GetManufacturerString(TDescriptionStrings &_ds) const
[取得] Description 文字列取得.
CUsbHidPathName(void)
コンストラクタ
const CStr & GetPathName(void) const
[取得] パスネーム取得
size_t GetInputReportByteLength(void) const
[取得] Inputレポート長取得
DWORD SetPathName(LPCTSTR lpszPathName)
[設定] パスネーム設定.
WORD GetProductId(void) const
[取得] プロダクトID取得
WORD GetVendorId(void) const
[取得] ベンダID取得
void Empty(void)
[設定] 情報なし
CStr GetLocationInformation(void) const
[取得] 場所情報取得.
CStr ToString(void) const
[取得] 文字列取得.
bool GetValueCaps(CWorkMemT< HIDP_VALUE_CAPS > &_vn, HIDP_REPORT_TYPE reportType)
[設定] 値性能情報取得.
bool GetButtonCaps(CWorkMemT< HIDP_BUTTON_CAPS > &_vn, HIDP_REPORT_TYPE reportType)
[設定] ボタン性能情報取得.
size_t GetFeatureReportByteLength(void) const
[取得] Featureレポート長取得
DWORD GetMajorVersion(void) const
[取得] メジャーバージョン取得.
size_t GetSize(void) const
[取得] サイズ取得
void Resize(size_t l)
[設定] サイズ再設定
const TYP * Ref(void) const
[取得] ポインタ取得
CStr QueryString(LPCTSTR lpszKey, LPCTSTR lpszDefault=NULL) const
[取得] 文字列情報取得
CStr GetSectionName(void) const
[取得] セクション名取得
void Zero(V &value)
[設定] ゼロクリア.
CStr serialNumber
SerialNumber 文字列
CStr manufacturer
Manufacturer 文字列
bool IsEmpty(void) const
[確認] 要素の有無確認.