ecdisp.c
来自「winddk src目录下的WDM源码压缩!」· C语言 代码 · 共 1,674 行 · 第 1/5 页
C
1,674 行
/*++
Copyright (c) Microsoft 1998, All Rights Reserved
Module Name:
ecdisp.c
Abstract:
This module contains the code to handle the extended calls dialog box
and the actions that can be performed in the dialog box.
Environment:
User mode
Revision History:
May-98 : Created
--*/
/*****************************************************************************
/* Extended call display include files
/*****************************************************************************/
#include <windows.h>
#include <limits.h>
#include <stdlib.h>
#include <math.h>
#include <stdio.h>
#include <setupapi.h>
#include <vfw.h>
#include <assert.h>
#include "hidusage.h"
#include "hidsdi.h"
#include "hid.h"
#include "hclient.h"
#include "resource.h"
#include "buffers.h"
#include "ecdisp.h"
#include "strings.h"
#include <strsafe.h>
/*****************************************************************************
/* Local macro definitions for the supported function calls
/*****************************************************************************/
#define HID_DEVCALLS 20
#define HID_PPDCALLS 29
#define HID_NUMCALLS HID_DEVCALLS + HID_PPDCALLS
#define HIDD_GET_HID_GUID 1
#define HIDD_GET_FREE_PREPARSED_DATA 2
#define HIDD_GET_CONFIGURATION 3
#define HIDD_SET_CONFIGURATION 4
#define HIDD_FLUSH_QUEUE 5
#define HIDD_GET_ATTRIBUTES 6
#define HIDD_SET_FEATURE 7
#define HIDD_GET_FEATURE 8
#define HIDD_GET_INPUT_REPORT 9
#define HIDD_SET_OUTPUT_REPORT 10
#define HIDD_GET_NUM_INPUT_BUFFERS 11
#define HIDD_SET_NUM_INPUT_BUFFERS 12
#define HIDD_GET_PHYSICAL_DESCRIPTOR 13
#define HIDD_GET_MANUFACTURER_STRING 14
#define HIDD_GET_PRODUCT_STRING 15
#define HIDD_GET_INDEXED_STRING 16
#define HIDD_GET_SERIAL_NUMBER_STRING 17
#define HIDD_GET_MS_GENRE_DESCRIPTOR 18
#define HID_READ_REPORT 19
#define HID_WRITE_REPORT 20
#define HIDP_GET_BUTTON_CAPS 21
#define HIDP_GET_BUTTONS 22
#define HIDP_GET_BUTTONS_EX 23
#define HIDP_GET_CAPS 24
#define HIDP_GET_DATA 25
#define HIDP_GET_EXTENDED_ATTRIBUTES 26
#define HIDP_GET_LINK_COLL_NODES 27
#define HIDP_GET_SCALED_USAGE_VALUE 28
#define HIDP_GET_SPECIFIC_BUTTON_CAPS 29
#define HIDP_GET_SPECIFIC_VALUE_CAPS 30
#define HIDP_GET_USAGES 31
#define HIDP_GET_USAGES_EX 32
#define HIDP_GET_USAGE_VALUE 33
#define HIDP_GET_USAGE_VALUE_ARRAY 34
#define HIDP_GET_VALUE_CAPS 35
#define HIDP_INITIALIZE_REPORT_FOR_ID 36
#define HIDP_MAX_DATA_LIST_LENGTH 37
#define HIDP_MAX_USAGE_LIST_LENGTH 38
#define HIDP_SET_BUTTONS 39
#define HIDP_SET_DATA 40
#define HIDP_SET_SCALED_USAGE_VALUE 41
#define HIDP_SET_USAGES 42
#define HIDP_SET_USAGE_VALUE 43
#define HIDP_SET_USAGE_VALUE_ARRAY 44
#define HIDP_TRANSLATE_USAGES 45
#define HIDP_UNSET_BUTTONS 46
#define HIDP_UNSET_USAGES 47
#define HIDP_USAGE_LIST_DIFFERENCE 48
#define HID_CLEAR_REPORT 49
/*
// These two definitions are not used by the display routines since
// the two functions were molded together into one for purpose of execution
*/
#define HIDD_GET_PREPARSED_DATA 50
#define HIDD_FREE_PREPARSED_DATA 51
#define IS_HIDD_FUNCTION(func) (((func) >= HIDD_GET_HID_GUID) && \
((func) <= HIDD_GET_MS_GENRE_DESCRIPTOR))
#define IS_HIDP_FUNCTION(func) (((func) >= HIDP_GET_BUTTON_CAPS) && \
((func) <= HIDP_USAGE_LIST_DIFFERENCE))
#define IS_HID_FUNCTION(func) (((func) >= HID_READ_REPORT) && \
((func) <= HID_WRITE_REPORT))
#define IS_NOT_IMPLEMENTED(func) (((func) == HIDD_GET_CONFIGURATION) || \
((func) == HIDD_SET_CONFIGURATION) || \
((func) == HIDP_TRANSLATE_USAGES) || \
(((func) == HIDP_INITIALIZE_REPORT_FOR_ID) && \
(NULL == pfnHidP_InitializeReportForID)) || \
(((func) == HIDP_GET_EXTENDED_ATTRIBUTES) && \
(NULL == pfnHidP_GetExtendedAttributes)))
/*****************************************************************************
/* Local macro definitions for buffer display sizes
/*****************************************************************************/
#define NUM_INPUT_BUFFERS 16
#define NUM_OUTPUT_BUFFERS 16
#define NUM_FEATURE_BUFFERS 16
/*****************************************************************************
/* Local macro definition for HidP_SetData dialog box
/*****************************************************************************/
#define SETDATA_LISTBOX_FORMAT "Index: %u, DataValue: %u"
/*****************************************************************************
/* Local macro definition for display output to output windows
/*****************************************************************************/
#define TEMP_BUFFER_SIZE 1024
#define OUTSTRING(win, str) SendMessage(win, LB_ADDSTRING, 0, (LPARAM) str)
#define OUTWSTRING(win, str) \
{ \
SIZE_T nBytes; \
\
nBytes = wcstombs(szTempBuffer, str, TEMP_BUFFER_SIZE-1); \
if ((SIZE_T) -1 == nBytes) { \
OUTSTRING(win, "Cannot convert wide-character string"); \
} \
else { \
szTempBuffer[nBytes] = '\0'; \
OUTSTRING(win, szTempBuffer); \
} \
}
#define DISPLAY_HIDD_STATUS(win, func, status, strret) \
{ \
strret = StringCbPrintf(szTempBuffer, \
TEMP_BUFFER_SIZE, \
"%s returned: %s", \
func, \
(status).IsHidError ? "FALSE" : "TRUE"); \
\
OUTSTRING(win, szTempBuffer); \
\
if ((status).IsHidError) { \
strret = StringCbPrintf(szTempBuffer, \
TEMP_BUFFER_SIZE, \
"ErrorCode: %d", \
GetLastError()); \
}\
OUTSTRING(win, szTempBuffer); \
}
#define DISPLAY_HIDP_STATUS(win, func, status, strret) \
{ \
strret = StringCbPrintf(szTempBuffer, \
TEMP_BUFFER_SIZE, \
"%s returned: %s", \
func, \
ECDisp_GetHidAppStatusString(status.HidErrorCode)); \
\
OUTSTRING(win, szTempBuffer); \
}
#define ECDISP_ERROR(win, msg) \
{ \
MessageBox(win, \
msg, \
HCLIENT_ERROR, \
MB_ICONEXCLAMATION); \
}
#define GET_FUNCTION_NAME(index) ResolveFunctionName(index)
/*****************************************************************************
/* Local macro definition for retrieving data based on report type
/*****************************************************************************/
#define SELECT_ON_REPORT_TYPE(rt, ival, oval, fval, res) \
{ \
switch ((rt)) { \
case HidP_Input: \
(res) = (ival); \
break; \
\
case HidP_Output: \
(res) = (oval); \
break; \
\
case HidP_Feature: \
(res) = (fval); \
break; \
\
} \
}
/*****************************************************************************
/* Local macro definition for calculating size of a usage value array buffer
/*****************************************************************************/
#define ROUND_TO_NEAREST_BYTE(val) (((val) % 8) ? ((val) / 8) + 1 : ((val) / 8))
/*****************************************************************************
/* Data types local to this module
/*****************************************************************************/
typedef struct _FUNCTION_NAMES
{
UINT uiIndex;
char *szFunctionName;
} FUNCTION_NAMES;
typedef struct _PARAMETER_STATE
{
BOOL fInputReport;
BOOL fOutputReport;
BOOL fFeatureReport;
BOOL fReportID;
BOOL fUsagePage;
BOOL fUsage;
BOOL fLinkCollection;
BOOL fInputReportSelect;
BOOL fOutputReportSelect;
BOOL fFeatureReportSelect;
} PARAMETER_STATE;
typedef enum { DLGBOX_INIT_FAILED = -1, DLGBOX_ERROR, DLGBOX_CANCEL, DLGBOX_OK } DLGBOX_STATUS;
typedef struct _ECDISPLAY_PARAMS
{
HIDP_REPORT_TYPE ReportType;
USAGE UsagePage;
USAGE Usage;
USHORT LinkCollection;
UCHAR ReportID;
PCHAR szListString;
PCHAR szListString2;
PUSAGE UsageList;
PUSAGE UsageList2;
ULONG ListLength;
ULONG ListLength2;
ULONG Index;
union {
PHIDP_DATA pDataList;
PULONG pValueList;
LONG ScaledValue;
ULONG Value;
};
} ECDISPLAY_PARAMS, *PECDISPLAY_PARAMS;
typedef struct _READ_PARAMS
{
PHID_DEVICE device;
BOOLEAN stopThread;
} READ_PARAMS, *PREAD_PARAMS;
/*****************************************************************************
/* Local data variables
/*****************************************************************************/
static CHAR szTempBuffer[TEMP_BUFFER_SIZE];
static PBUFFER_DISPLAY pInputDisplay;
static PBUFFER_DISPLAY pOutputDisplay;
static PBUFFER_DISPLAY pFeatureDisplay;
static FUNCTION_NAMES DeviceCalls[HID_DEVCALLS] = {
{ HIDD_GET_HID_GUID, "HidD_GetHidGuid" },
{ HIDD_GET_FREE_PREPARSED_DATA, "HidD_GetFreePreparsedData" },
{ HIDD_GET_CONFIGURATION, "HidD_GetConfiguration" },
{ HIDD_SET_CONFIGURATION, "HidD_SetConfiguration" },
{ HIDD_FLUSH_QUEUE, "HidD_FlushQueue" },
{ HIDD_GET_ATTRIBUTES, "HidD_GetAttributes" },
{ HIDD_SET_FEATURE, "HidD_SetFeature" },
{ HIDD_GET_FEATURE, "HidD_GetFeature" },
{ HIDD_GET_INPUT_REPORT, "HIDD_GetInputReport" },
{ HIDD_SET_OUTPUT_REPORT, "HidD_SetOutputReport" },
{ HIDD_GET_NUM_INPUT_BUFFERS, "HidD_GetNumInputBuffers" },
{ HIDD_SET_NUM_INPUT_BUFFERS, "HidD_SetNumInputBuffers" },
{ HIDD_GET_PHYSICAL_DESCRIPTOR, "HidD_GetPhysicalDescriptor" },
{ HIDD_GET_MANUFACTURER_STRING, "HidD_GetManufacturerString" },
{ HIDD_GET_PRODUCT_STRING, "HidD_GetProductString" },
{ HIDD_GET_INDEXED_STRING, "HidD_GetIndexedString" },
{ HIDD_GET_SERIAL_NUMBER_STRING, "HidD_GetSerialNumberString" },
{ HIDD_GET_MS_GENRE_DESCRIPTOR, "HidD_GetMsGenreDescriptor" },
{ HID_READ_REPORT, "Read Input Report" },
{ HID_WRITE_REPORT, "Write Report Buffer" }
};
static FUNCTION_NAMES PpdCalls[HID_PPDCALLS] = {
{ HIDP_GET_BUTTON_CAPS, "HidP_GetButtonCaps" },
{ HIDP_GET_BUTTONS, "HidP_GetButtons" },
{ HIDP_GET_BUTTONS_EX, "HidP_GetButtonsEx" },
{ HIDP_GET_CAPS, "HidP_GetCaps" },
{ HIDP_GET_DATA, "HidP_GetData" },
{ HIDP_GET_EXTENDED_ATTRIBUTES, "HidP_GetExtendedAttributes" },
{ HIDP_GET_LINK_COLL_NODES, "HidP_GetLinkCollectionNodes" },
{ HIDP_GET_SCALED_USAGE_VALUE, "HidP_GetScaledUsageValue" },
{ HIDP_GET_SPECIFIC_BUTTON_CAPS, "HidP_GetSpecificButtonCaps" },
{ HIDP_GET_SPECIFIC_VALUE_CAPS, "HidP_GetSpecificValueCaps" },
{ HIDP_GET_USAGES, "HidP_GetUsages" },
{ HIDP_GET_USAGES_EX, "HidP_GetUsagesEx" },
{ HIDP_GET_USAGE_VALUE, "HidP_GetUsageValue" },
{ HIDP_GET_USAGE_VALUE_ARRAY, "HidP_GetUsageValueArray" },
{ HIDP_GET_VALUE_CAPS, "HidP_GetValueCaps" },
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?