Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

117 lines
3.7 KiB

  1. /*
  2. * CASHDRWR.C
  3. *
  4. * Point-of-Sale Control Panel Applet
  5. *
  6. * Author: Ervin Peretz
  7. *
  8. * (c) 2001 Microsoft Corporation
  9. */
  10. #include <windows.h>
  11. #include <windowsx.h>
  12. #include <commctrl.h>
  13. #include <cpl.h>
  14. #include <setupapi.h>
  15. #include <hidsdi.h>
  16. #include "internal.h"
  17. #include "res.h"
  18. #include "debug.h"
  19. #if USE_OVERLAPPED_IO
  20. VOID CALLBACK OverlappedWriteCompletionRoutine( DWORD dwErrorCode,
  21. DWORD dwNumberOfBytesTransfered,
  22. LPOVERLAPPED lpOverlapped)
  23. {
  24. posDevice *posDev;
  25. /*
  26. * We stashed our context in the hEvent field of the
  27. * overlapped structure (this is allowed).
  28. */
  29. ASSERT(lpOverlapped);
  30. posDev = lpOverlapped->hEvent;
  31. ASSERT(posDev->sig == POSCPL_SIG);
  32. posDev->overlappedWriteStatus = dwErrorCode;
  33. posDev->overlappedWriteLen = dwNumberOfBytesTransfered;
  34. SetEvent(posDev->overlappedWriteEvent);
  35. }
  36. #endif
  37. BOOL SetCashDrawerState(posDevice *posDev, enum cashDrawerStates newState)
  38. {
  39. NTSTATUS ntStat;
  40. BOOL result = FALSE;
  41. ASSERT(posDev->hidCapabilities.OutputReportByteLength <= 20);
  42. ntStat = HidP_SetUsageValue(HidP_Output,
  43. USAGE_PAGE_CASH_DEVICE,
  44. 0, // all collections
  45. USAGE_CASH_DRAWER_SET,
  46. newState,
  47. posDev->hidPreparsedData,
  48. posDev->writeBuffer,
  49. posDev->hidCapabilities.OutputReportByteLength);
  50. if (ntStat == HIDP_STATUS_SUCCESS){
  51. DWORD bytesWritten = 0;
  52. BOOL ok;
  53. ASSERT(posDev->hidCapabilities.OutputReportByteLength > 0);
  54. ASSERT(posDev->writeBuffer);
  55. #if USE_OVERLAPPED_IO
  56. /*
  57. * It's ok to stash our context in the hEvent field
  58. * of the overlapped structure.
  59. */
  60. posDev->overlappedWriteInfo.hEvent = (HANDLE)posDev;
  61. posDev->overlappedWriteInfo.Offset = 0;
  62. posDev->overlappedWriteInfo.OffsetHigh = 0;
  63. posDev->overlappedWriteLen = 0;
  64. ResetEvent(posDev->overlappedWriteEvent);
  65. ok = WriteFileEx( posDev->devHandle,
  66. posDev->writeBuffer,
  67. posDev->hidCapabilities.OutputReportByteLength,
  68. &posDev->overlappedWriteInfo,
  69. OverlappedWriteCompletionRoutine);
  70. if (ok){
  71. WaitForSingleObject(posDev->overlappedWriteEvent, INFINITE);
  72. ok = (posDev->overlappedWriteStatus == NO_ERROR);
  73. bytesWritten = posDev->overlappedWriteLen;
  74. }
  75. else {
  76. bytesWritten = 0;
  77. }
  78. #else
  79. ok = WriteFile( posDev->devHandle,
  80. posDev->writeBuffer,
  81. posDev->hidCapabilities.OutputReportByteLength,
  82. &bytesWritten,
  83. NULL);
  84. #endif
  85. if (ok){
  86. ASSERT(bytesWritten <= posDev->hidCapabilities.OutputReportByteLength);
  87. result = TRUE;
  88. }
  89. else {
  90. DWORD err = GetLastError();
  91. DBGERR(L"WriteFile failed", err);
  92. }
  93. }
  94. else {
  95. DBGERR(L"HidP_SetUsageValue failed", ntStat);
  96. DBGERR(DBGHIDSTATUSSTR(ntStat), 0);
  97. }
  98. return result;
  99. }