diff options
| author | karlf <[email protected]> | 2016-08-11 13:28:13 -0700 |
|---|---|---|
| committer | karlf <[email protected]> | 2016-08-11 13:28:13 -0700 |
| commit | 96eb96dfb613e4c745db6bd1f53a92fe7e2290fc (patch) | |
| tree | ad5f3ede5cbcd6b598677ce41bcf8318471bdd92 /hid/hclient | |
| parent | 687b274aa38fd05c8c26e3068932121876d7f745 (diff) | |
Updated for "Windows 10 Anniversary Update" (Version 1607)
Diffstat (limited to 'hid/hclient')
| -rw-r--r-- | hid/hclient/ecdisp.c | 40 | ||||
| -rw-r--r-- | hid/hclient/hclient.c | 118 | ||||
| -rw-r--r-- | hid/hclient/hclient.sln | 18 | ||||
| -rw-r--r-- | hid/hclient/hclient.vcxproj | 4 | ||||
| -rw-r--r-- | hid/hclient/hclient.vcxproj.Filters | 6 | ||||
| -rw-r--r-- | hid/hclient/hid.h | 3 | ||||
| -rw-r--r-- | hid/hclient/report.c | 36 |
7 files changed, 159 insertions, 66 deletions
diff --git a/hid/hclient/ecdisp.c b/hid/hclient/ecdisp.c index 5d25aa4c..0d15774f 100644 --- a/hid/hclient/ecdisp.c +++ b/hid/hclient/ecdisp.c @@ -650,6 +650,7 @@ bExtCallDlgProc( static INT nFeatureReportIDs; static HANDLE ReadThread; static READ_THREAD_CONTEXT readContext; + static HID_DEVICE device; INT iIndex; ECDISPLAY_PARAMS params; @@ -770,9 +771,25 @@ bExtCallDlgProc( if (NULL == ReadThread) { - readContext.HidDevice = pDevice; + if (!OpenHidDevice(pDevice->DevicePath, + TRUE, + FALSE, + (LOWORD(wParam) == IDC_READ_SYNCH) ? FALSE : TRUE, + FALSE, + &device)) + { + MessageBox(hDlg, + "Failed opening the device for read.", + HCLIENT_ERROR, + MB_ICONEXCLAMATION); + break; + } + + SendDlgItemMessage(hDlg, IDC_CALLOUTPUT, LB_RESETCONTENT, 0, 0); + + readContext.HidDevice = &device; readContext.TerminateThread = FALSE; - readContext.NumberOfReads = 1; + readContext.NumberOfReads = INFINITE_READS; readContext.DisplayEvent = NULL; readContext.DisplayWindow = hDlg; @@ -792,7 +809,7 @@ bExtCallDlgProc( HCLIENT_ERROR, MB_ICONEXCLAMATION); } - else + else { EnableWindow(GetDlgItem(hDlg, IDC_READ_SYNCH), (LOWORD(wParam) == IDC_READ_SYNCH)); @@ -802,16 +819,18 @@ bExtCallDlgProc( SetWindowText(GetDlgItem(hDlg, LOWORD(wParam)), "Stop Read Thread"); - + EnableWindow(GetDlgItem(hDlg, IDC_CANCEL), FALSE); } } - else + else { readContext.TerminateThread = TRUE; WaitForSingleObject(ReadThread, INFINITE); + CloseHidDevice(&device); + ReadThread = NULL; SetWindowText(GetDlgItem(hDlg, IDC_READ_SYNCH), @@ -820,11 +839,11 @@ bExtCallDlgProc( SetWindowText(GetDlgItem(hDlg, IDC_READ_ASYNCH), "Start Asynchronous Read Thread"); - EnableWindow(GetDlgItem(hDlg, IDC_READ_SYNCH), TRUE); - EnableWindow(GetDlgItem(hDlg, IDC_READ_ASYNCH), TRUE); - EnableWindow(GetDlgItem(hDlg, IDC_CANCEL), TRUE); - } - break; + EnableWindow(GetDlgItem(hDlg, IDC_READ_SYNCH), TRUE); + EnableWindow(GetDlgItem(hDlg, IDC_READ_ASYNCH), TRUE); + EnableWindow(GetDlgItem(hDlg, IDC_CANCEL), TRUE); + } + break; case IDC_CANCEL: BufferDisplay_Destroy(pInputDisplay); @@ -2643,7 +2662,6 @@ RoutineDescription: ¶ms -> ListLength); free(params -> szListString); params->szListString = NULL; - params->ListLength = 0; if (!ExecuteStatus) { diff --git a/hid/hclient/hclient.c b/hid/hclient/hclient.c index 09114bf3..62ca83fd 100644 --- a/hid/hclient/hclient.c +++ b/hid/hclient/hclient.c @@ -752,7 +752,7 @@ CLM_AsyncRead( FALSE, &asyncDevice)) { - printf("Failed opening the device for synchronous read.\n"); + printf("Failed opening the device for asynchronous read.\n"); return; } @@ -2328,7 +2328,7 @@ bReadDlgProc( EnableWindow(GetDlgItem(hDlg, IDOK), FALSE); EnableWindow(GetDlgItem(hDlg, IDC_READ_SYNCH), FALSE); EnableWindow(GetDlgItem(hDlg, IDC_READ_ASYNCH_ONCE), FALSE); - EnableWindow(GetDlgItem(hDlg, IDC_READ_ASYNCH_CONT), FALSE); + EnableWindow(GetDlgItem(hDlg, IDC_READ_ASYNCH_CONT), FALSE); Read(&syncDevice); @@ -2379,7 +2379,7 @@ bReadDlgProc( IDC_READ_ASYNCH_ONCE == LOWORD(wParam)); EnableWindow(GetDlgItem(hDlg, IDC_READ_ASYNCH_CONT), - IDC_READ_ASYNCH_CONT == LOWORD(wParam)); + IDC_READ_ASYNCH_CONT == LOWORD(wParam)); SetWindowText(GetDlgItem(hDlg, LOWORD(wParam)), "Stop Asynchronous Read"); @@ -2394,7 +2394,7 @@ bReadDlgProc( readContext.TerminateThread = TRUE; WaitForSingleObject(readThread, INFINITE); - } + } break; case IDCANCEL: @@ -2402,8 +2402,9 @@ bReadDlgProc( WaitForSingleObject(readThread, INFINITE); //Fall through!!! - case IDOK: - CloseHidDevice(&asyncDevice); + case IDOK: + CloseHidDevice(&asyncDevice); + CloseHidDevice(&syncDevice); EndDialog(hDlg,0); break; } @@ -3697,9 +3698,12 @@ AsynchReadThreadProc( ) { HANDLE completionEvent; - BOOL readStatus; + BOOL readResult; DWORD waitStatus; ULONG numReadsDone; + OVERLAPPED overlap; + DWORD bytesTransferred; + // // Create the completion event to send to the the OverlappedRead routine @@ -3743,10 +3747,10 @@ AsynchReadThreadProc( // exit // - readStatus = ReadOverlapped( Context -> HidDevice, completionEvent ); + readResult = ReadOverlapped( Context->HidDevice, completionEvent, &overlap ); - - if (!readStatus) + + if (!readResult) { break; } @@ -3761,11 +3765,12 @@ AsynchReadThreadProc( // // If completionEvent was signaled, then a read just completed - // so let's leave this loop and process the data + // so let's get the status and leave this loop and process the data // if ( WAIT_OBJECT_0 == waitStatus) - { + { + readResult = GetOverlappedResult(Context->HidDevice->HidDevice, &overlap, &bytesTransferred, TRUE); break; } } @@ -3788,8 +3793,8 @@ AsynchReadThreadProc( Context -> HidDevice -> InputDataLength, Context -> HidDevice -> Ppd); - if (NULL != Context -> DisplayEvent) - { + if (NULL != Context -> DisplayEvent) + { PostMessage(Context -> DisplayWindow, WM_DISPLAY_READ_DATA, 0, @@ -3797,6 +3802,37 @@ AsynchReadThreadProc( WaitForSingleObject( Context -> DisplayEvent, INFINITE ); } + else if (NULL != Context->DisplayWindow) + { + CHAR szTempBuff[1024]; + PHID_DEVICE pDevice; + PHID_DATA pData; + UINT uLoop; + + pDevice = (PHID_DEVICE)Context->HidDevice; + + // + // Display all the data stored in the Input data field for the device + // + pData = pDevice->InputData; + + SendMessage(GetDlgItem(Context->DisplayWindow, IDC_CALLOUTPUT), + LB_ADDSTRING, + 0, + (LPARAM)"-------------------------------------------"); + + for (uLoop = 0; uLoop < pDevice->InputDataLength; uLoop++) + { + ReportToString(pData, szTempBuff, sizeof(szTempBuff)); + + SendMessage(GetDlgItem(Context->DisplayWindow, IDC_CALLOUTPUT), + LB_ADDSTRING, + 0, + (LPARAM)szTempBuff); + + pData++; + } + } else if (NULL == Context -> DisplayWindow) { // Running in console mode @@ -3804,9 +3840,10 @@ AsynchReadThreadProc( CLM_PrintInputReport(Context -> HidDevice); } } - } while ( !Context -> TerminateThread && + } while ( readResult && + !Context->TerminateThread && (INFINITE_READS == Context -> NumberOfReads || - numReadsDone < Context -> NumberOfReads)); + numReadsDone < Context -> NumberOfReads)); AsyncRead_End: @@ -3825,7 +3862,11 @@ SynchReadThreadProc( do { Read(Context -> HidDevice); - + + if (Context->TerminateThread) { + break; + } + numReadsDone ++; UnpackReport(Context -> HidDevice -> InputReportBuffer, @@ -3844,13 +3885,46 @@ SynchReadThreadProc( WaitForSingleObject( Context -> DisplayEvent, INFINITE ); } - - if (INFINITE_READS != Context -> NumberOfReads && - numReadsDone == Context -> NumberOfReads) + else if (NULL != Context->DisplayWindow) { - break; + CHAR szTempBuff[1024]; + PHID_DEVICE pDevice; + PHID_DATA pData; + UINT uLoop; + + pDevice = (PHID_DEVICE)Context->HidDevice; + + // + // Display all the data stored in the Input data field for the device + // + pData = pDevice->InputData; + + SendMessage(GetDlgItem(Context->DisplayWindow, IDC_CALLOUTPUT), + LB_ADDSTRING, + 0, + (LPARAM)"-------------------------------------------"); + + for (uLoop = 0; uLoop < pDevice->InputDataLength; uLoop++) + { + ReportToString(pData, szTempBuff, sizeof(szTempBuff)); + + SendMessage(GetDlgItem(Context->DisplayWindow, IDC_CALLOUTPUT), + LB_ADDSTRING, + 0, + (LPARAM)szTempBuff); + + pData++; + } + } + else if (NULL == Context->DisplayWindow) + { + // Running in console mode + printf("Read #%d\n", numReadsDone); + CLM_PrintInputReport(Context->HidDevice); } - } while ( !Context -> TerminateThread); + } while (!Context->TerminateThread && + (INFINITE_READS == Context->NumberOfReads || + numReadsDone < Context->NumberOfReads)); PostMessage( Context -> DisplayWindow, WM_READ_DONE, 0, 0); ExitThread(0); diff --git a/hid/hclient/hclient.sln b/hid/hclient/hclient.sln index a2ed0c44..994bc4e9 100644 --- a/hid/hclient/hclient.sln +++ b/hid/hclient/hclient.sln @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 2013 VisualStudioVersion = 12.0 MinimumVisualStudioVersion = 12.0 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "hclient", "hclient.vcxproj", "{7A7D6960-DBAA-4A93-8C8C-833FD9F31D44}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "hclient", "hclient.vcxproj", "{1C842832-07EF-4A86-B46F-8CE77446E7FE}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -13,14 +13,14 @@ Global Release|x64 = Release|x64 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {7A7D6960-DBAA-4A93-8C8C-833FD9F31D44}.Debug|Win32.ActiveCfg = Debug|Win32 - {7A7D6960-DBAA-4A93-8C8C-833FD9F31D44}.Debug|Win32.Build.0 = Debug|Win32 - {7A7D6960-DBAA-4A93-8C8C-833FD9F31D44}.Release|Win32.ActiveCfg = Release|Win32 - {7A7D6960-DBAA-4A93-8C8C-833FD9F31D44}.Release|Win32.Build.0 = Release|Win32 - {7A7D6960-DBAA-4A93-8C8C-833FD9F31D44}.Debug|x64.ActiveCfg = Debug|x64 - {7A7D6960-DBAA-4A93-8C8C-833FD9F31D44}.Debug|x64.Build.0 = Debug|x64 - {7A7D6960-DBAA-4A93-8C8C-833FD9F31D44}.Release|x64.ActiveCfg = Release|x64 - {7A7D6960-DBAA-4A93-8C8C-833FD9F31D44}.Release|x64.Build.0 = Release|x64 + {1C842832-07EF-4A86-B46F-8CE77446E7FE}.Debug|Win32.ActiveCfg = Debug|Win32 + {1C842832-07EF-4A86-B46F-8CE77446E7FE}.Debug|Win32.Build.0 = Debug|Win32 + {1C842832-07EF-4A86-B46F-8CE77446E7FE}.Release|Win32.ActiveCfg = Release|Win32 + {1C842832-07EF-4A86-B46F-8CE77446E7FE}.Release|Win32.Build.0 = Release|Win32 + {1C842832-07EF-4A86-B46F-8CE77446E7FE}.Debug|x64.ActiveCfg = Debug|x64 + {1C842832-07EF-4A86-B46F-8CE77446E7FE}.Debug|x64.Build.0 = Debug|x64 + {1C842832-07EF-4A86-B46F-8CE77446E7FE}.Release|x64.ActiveCfg = Release|x64 + {1C842832-07EF-4A86-B46F-8CE77446E7FE}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/hid/hclient/hclient.vcxproj b/hid/hclient/hclient.vcxproj index 1ad38b14..e2983fd4 100644 --- a/hid/hclient/hclient.vcxproj +++ b/hid/hclient/hclient.vcxproj @@ -19,11 +19,11 @@ </ProjectConfiguration> </ItemGroup> <PropertyGroup Label="Globals"> - <ProjectGuid>{7A7D6960-DBAA-4A93-8C8C-833FD9F31D44}</ProjectGuid> + <ProjectGuid>{1C842832-07EF-4A86-B46F-8CE77446E7FE}</ProjectGuid> <RootNamespace>$(MSBuildProjectName)</RootNamespace> <Configuration Condition="'$(Configuration)' == ''">Debug</Configuration> <Platform Condition="'$(Platform)' == ''">Win32</Platform> - <SampleGuid>{D88F2866-9D6E-437A-8F8D-056B18E851AF}</SampleGuid> + <SampleGuid>{8CC30BF0-571B-467D-83C8-3B11A862C64F}</SampleGuid> </PropertyGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> <PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> diff --git a/hid/hclient/hclient.vcxproj.Filters b/hid/hclient/hclient.vcxproj.Filters index b2f5d62f..0ed5fb00 100644 --- a/hid/hclient/hclient.vcxproj.Filters +++ b/hid/hclient/hclient.vcxproj.Filters @@ -3,15 +3,15 @@ <ItemGroup> <Filter Include="Source Files"> <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx;*</Extensions> - <UniqueIdentifier>{55093100-B347-4736-B0EC-F835DDA0D98D}</UniqueIdentifier> + <UniqueIdentifier>{EB720146-929F-413C-B049-B32470411E52}</UniqueIdentifier> </Filter> <Filter Include="Header Files"> <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions> - <UniqueIdentifier>{43D41B7E-82A6-4508-B577-4B2702FA8C8C}</UniqueIdentifier> + <UniqueIdentifier>{6586AAE7-53D0-4A11-8109-C63A954F3160}</UniqueIdentifier> </Filter> <Filter Include="Resource Files"> <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms;man;xml</Extensions> - <UniqueIdentifier>{2B0259E8-4B79-49E6-BAEE-57D0FB83FFC8}</UniqueIdentifier> + <UniqueIdentifier>{C96865A4-45B5-443D-9669-8FB25940EEED}</UniqueIdentifier> </Filter> </ItemGroup> <ItemGroup> diff --git a/hid/hclient/hid.h b/hid/hclient/hid.h index af149ba7..e9a8b09e 100644 --- a/hid/hclient/hid.h +++ b/hid/hclient/hid.h @@ -158,7 +158,8 @@ Read ( BOOLEAN ReadOverlapped ( PHID_DEVICE HidDevice, - HANDLE CompletionEvent + HANDLE CompletionEvent, + LPOVERLAPPED Overlap ); BOOLEAN diff --git a/hid/hclient/report.c b/hid/hclient/report.c index 6734092f..f1d9ee55 100644 --- a/hid/hclient/report.c +++ b/hid/hclient/report.c @@ -8,8 +8,8 @@ Module Name: Abstract: - This module contains the code for reading/writing hid reports and - translating those HID reports into useful information. + This module contains the code for reading/writing hid reports and + translating those HID reports into useful information. Environment: @@ -64,7 +64,8 @@ Done: BOOLEAN ReadOverlapped ( PHID_DEVICE HidDevice, - HANDLE CompletionEvent + HANDLE CompletionEvent, + LPOVERLAPPED Overlap ) /*++ RoutineDescription: @@ -72,7 +73,6 @@ RoutineDescription: into the InputData array. --*/ { - static OVERLAPPED overlap; DWORD bytesRead; BOOL readStatus; @@ -81,10 +81,10 @@ RoutineDescription: // to use for signalling the completion of the Read */ - memset(&overlap, 0, sizeof(OVERLAPPED)); - - overlap.hEvent = CompletionEvent; - + memset(Overlap, 0, sizeof(OVERLAPPED)); + + Overlap->hEvent = CompletionEvent; + /* // Execute the read call saving the return code to determine how to // proceed (ie. the read completed synchronously or not). @@ -94,20 +94,20 @@ RoutineDescription: HidDevice -> InputReportBuffer, HidDevice -> Caps.InputReportByteLength, &bytesRead, - &overlap); - + Overlap); + /* - // If the readStatus is FALSE, then one of two cases occurred. + // If the readStatus is FALSE, then one of two cases occurred. // 1) ReadFile call succeeded but the Read is an overlapped one. Here, // we should return TRUE to indicate that the Read succeeded. However, // the calling thread should be blocked on the completion event // which means it won't continue until the read actually completes - // + // // 2) The ReadFile call failed for some unknown reason...In this case, // the return code will be FALSE - */ + */ - if (!readStatus) + if (!readStatus) { return (ERROR_IO_PENDING == GetLastError()); } @@ -149,7 +149,7 @@ RoutineDescription: pData = HidDevice -> OutputData; - for (Index = 0; Index < HidDevice -> OutputDataLength; Index++, pData++) + for (Index = 0; Index < HidDevice -> OutputDataLength; Index++, pData++) { pData -> IsDataSet = FALSE; } @@ -164,14 +164,14 @@ RoutineDescription: Status = TRUE; pData = HidDevice -> OutputData; - for (Index = 0; Index < HidDevice -> OutputDataLength; Index++, pData++) + for (Index = 0; Index < HidDevice -> OutputDataLength; Index++, pData++) { if (!pData -> IsDataSet) { /* // Package the report for this data structure. PackReport will - // set the IsDataSet fields of this structure and any other + // set the IsDataSet fields of this structure and any other // structures that it includes in the report with this structure */ @@ -192,7 +192,7 @@ RoutineDescription: &bytesWritten, NULL) && (bytesWritten == HidDevice -> Caps.OutputReportByteLength); - Status = Status && WriteStatus; + Status = Status && WriteStatus; } } return (Status); |
