Source code of Windows XP (NT5)
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.

194 lines
6.4 KiB

  1. /*
  2. * DEBUG.CPP
  3. *
  4. *
  5. *
  6. *
  7. *
  8. *
  9. */
  10. #include <windows.h>
  11. #include <hidclass.h>
  12. #include <hidsdi.h>
  13. #include <setupapi.h>
  14. #include <ole2.h>
  15. #include <ole2ver.h>
  16. #include "..\inc\opos.h"
  17. #include "oposserv.h"
  18. VOID Report(LPSTR szMsg, DWORD num)
  19. {
  20. char msg[MAX_PATH];
  21. wsprintf((LPSTR)msg, "%s (%xh=%d).", szMsg, num, num);
  22. MessageBox((HWND)NULL, (LPSTR)msg, (LPCSTR)"OPOSSERV", MB_OK|MB_ICONEXCLAMATION);
  23. }
  24. void Test()
  25. {
  26. HDEVINFO hDevInfo;
  27. Report("Test()", 0);
  28. hDevInfo = SetupDiGetClassDevs(
  29. (LPGUID)&GUID_CLASS_INPUT, // BUGBUG change to POS
  30. NULL,
  31. NULL,
  32. DIGCF_DEVICEINTERFACE | DIGCF_PRESENT);
  33. if (hDevInfo == INVALID_HANDLE_VALUE){
  34. Report("SetupDiGetClassDevs failed", (DWORD)GetLastError());
  35. }
  36. else {
  37. SP_DEVICE_INTERFACE_DATA deviceData;
  38. BOOLEAN enumOk;
  39. DWORD memberIndex = 0;
  40. deviceData.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
  41. do {
  42. enumOk = SetupDiEnumDeviceInterfaces(
  43. hDevInfo,
  44. NULL,
  45. (LPGUID)&GUID_CLASS_INPUT,
  46. memberIndex,
  47. &deviceData
  48. );
  49. if (enumOk){
  50. CHAR detailBuf[MAX_PATH+1+sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA)] = "";
  51. PSP_DEVICE_INTERFACE_DETAIL_DATA detailData = (PSP_DEVICE_INTERFACE_DETAIL_DATA)&detailBuf;
  52. BOOLEAN getDetailOk;
  53. DWORD requiredSize;
  54. Report("SetupDiEnumDeviceInterfaces succeeded", 0);
  55. detailData->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
  56. getDetailOk = SetupDiGetDeviceInterfaceDetail(
  57. hDevInfo,
  58. &deviceData,
  59. detailData,
  60. sizeof(detailBuf),
  61. &requiredSize,
  62. NULL
  63. );
  64. if (getDetailOk){
  65. HANDLE hFile;
  66. Report(detailData->DevicePath, 0);
  67. hFile = CreateFile(
  68. detailData->DevicePath,
  69. GENERIC_READ | GENERIC_WRITE, // | SYNCHRONIZE | FILE_READ_ATTRIBUTES,
  70. FILE_SHARE_READ | FILE_SHARE_WRITE,
  71. NULL, // BUGBUG ? LPSECURITY_ATTRIBUTES lpSecurityAttributes,
  72. OPEN_EXISTING,
  73. FILE_ATTRIBUTE_NORMAL, // | FILE_FLAG_OVERLAPPED,
  74. 0);
  75. if (hFile == INVALID_HANDLE_VALUE){
  76. Report("CreateFile failed", (DWORD)GetLastError());
  77. }
  78. else {
  79. BOOL readOk;
  80. PCHAR alignedReadPtr;
  81. DWORD bytesRead = 0;
  82. // OVERLAPPED overlapped;
  83. Report("CreateFile succeeded", 0);
  84. #define BUF_SIZE 100000
  85. alignedReadPtr = (PCHAR)VirtualAlloc(NULL, BUF_SIZE, MEM_COMMIT, PAGE_READWRITE);
  86. if (alignedReadPtr){
  87. Report("Aligned read ptr is ", (DWORD)alignedReadPtr);
  88. do {
  89. // RtlZeroMemory(&overlapped, sizeof(OVERLAPPED));
  90. RtlZeroMemory(alignedReadPtr, BUF_SIZE);
  91. readOk = ReadFile(
  92. hFile,
  93. alignedReadPtr,
  94. 0x18, // BUGBUG
  95. &bytesRead,
  96. NULL // &overlapped
  97. );
  98. if (readOk){
  99. Report("ReadFile succeeded", bytesRead);
  100. }
  101. else {
  102. DWORD err = (DWORD)GetLastError();
  103. switch (err){
  104. case ERROR_INVALID_FUNCTION:
  105. Report("ReadFile: ERROR_INVALID_FUNCTION", err);
  106. break;
  107. case ERROR_ACCESS_DENIED:
  108. Report("ReadFile: ERROR_ACCESS_DENIED", err);
  109. break;
  110. case ERROR_INSUFFICIENT_BUFFER:
  111. Report("ReadFile: ERROR_INSUFFICIENT_BUFFER", err);
  112. break;
  113. case ERROR_IO_PENDING:
  114. Report("ReadFile: ERROR_IO_PENDING", err);
  115. break;
  116. default:
  117. Report("ReadFile failed", err);
  118. break;
  119. }
  120. Report("ReadFile: bytesRead = ", bytesRead);
  121. }
  122. } while (readOk);
  123. VirtualFree(alignedReadPtr, 0, MEM_RELEASE);
  124. }
  125. else {
  126. Report("Memory alloc failed", (DWORD)GetLastError);
  127. }
  128. CloseHandle(hFile);
  129. }
  130. }
  131. else {
  132. Report("SetupDiGetDeviceInterfaceDetail failed", (DWORD)GetLastError());
  133. }
  134. // BUGBUG - just look at the first one for now
  135. break;
  136. }
  137. else {
  138. DWORD err = GetLastError();
  139. switch (err){
  140. case ERROR_NO_MORE_ITEMS:
  141. Report("SetupDiEnumDeviceInterfaces: ERROR_NO_MORE_ITEMS", err);
  142. break;
  143. default:
  144. Report("SetupDiEnumDeviceInterfaces failed", err);
  145. break;
  146. }
  147. }
  148. memberIndex++;
  149. }
  150. while (enumOk);
  151. }
  152. Report("Test() done", 0);
  153. }