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.

182 lines
3.7 KiB

  1. #include "dfhlprs.h"
  2. #include <stdio.h>
  3. static DWORD dwStartTick = 0;
  4. static DWORD dwStopTick = 0;
  5. int _PrintIndent(DWORD cch)
  6. {
  7. // for now, stupid simple
  8. for (DWORD dw = 0; dw < cch; ++dw)
  9. {
  10. wprintf(TEXT(" "));
  11. }
  12. return cch;
  13. }
  14. int _PrintCR()
  15. {
  16. return wprintf(TEXT("\n"));
  17. }
  18. int _PrintGUID(CONST GUID* pguid)
  19. {
  20. return wprintf(L"{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
  21. pguid->Data1,
  22. pguid->Data2,
  23. pguid->Data3,
  24. pguid->Data4[0],
  25. pguid->Data4[1],
  26. pguid->Data4[2],
  27. pguid->Data4[3],
  28. pguid->Data4[4],
  29. pguid->Data4[5],
  30. pguid->Data4[6],
  31. pguid->Data4[7]);
  32. }
  33. int _PrintGUIDEx(CONST GUID* pguid, _sGUID_DESCR rgguid[], DWORD cguid,
  34. BOOL fPrintValue, DWORD cchIndent)
  35. {
  36. BOOL fFoundIt = FALSE;
  37. int i = _PrintIndent(cchIndent);
  38. for (DWORD dw = 0; dw < cguid; ++dw)
  39. {
  40. if (*(rgguid[dw].pguid) == *pguid)
  41. {
  42. i += wprintf(TEXT("%s"), rgguid[dw].pszDescr);
  43. fFoundIt = TRUE;
  44. break;
  45. }
  46. }
  47. if (fPrintValue)
  48. {
  49. if (fFoundIt)
  50. {
  51. i += wprintf(TEXT(", "));
  52. }
  53. i += _PrintGUID(pguid);
  54. }
  55. return i;
  56. }
  57. int _PrintGetLastError(DWORD cchIndent)
  58. {
  59. int i = _PrintIndent(cchIndent);
  60. i += wprintf(TEXT("GetLastError: 0x%08X"), GetLastError());
  61. return i;
  62. }
  63. void _StartClock()
  64. {
  65. dwStartTick = GetTickCount();
  66. }
  67. void _StopClock()
  68. {
  69. dwStopTick = GetTickCount();
  70. }
  71. int _PrintElapsedTime(DWORD cchIndent, BOOL fCarriageReturn)
  72. {
  73. int i = _PrintIndent(cchIndent);
  74. // consider wrap
  75. DWORD dwDiff = dwStopTick - dwStartTick;
  76. DWORD dwSec = dwDiff / 1000;
  77. DWORD dwMill = dwDiff % 1000;
  78. i += wprintf(TEXT("Elapsed time: %01d.%03d"), dwSec, dwMill);
  79. if (fCarriageReturn)
  80. {
  81. wprintf(TEXT("\n"));
  82. }
  83. return i;
  84. }
  85. int _PrintFlag(DWORD dwFlag, _sFLAG_DESCR rgflag[], DWORD cflag,
  86. DWORD cchIndent, BOOL fPrintValue, BOOL fHex, BOOL fComment, BOOL fORed)
  87. {
  88. int i = 0;
  89. BOOL fAtLeastOne = FALSE;
  90. for (DWORD dw = 0; dw < cflag; ++dw)
  91. {
  92. BOOL fPrint = FALSE;
  93. if (fORed)
  94. {
  95. if (rgflag[dw].dwFlag & dwFlag)
  96. {
  97. fPrint = TRUE;
  98. }
  99. }
  100. else
  101. {
  102. if (rgflag[dw].dwFlag == dwFlag)
  103. {
  104. fPrint = TRUE;
  105. }
  106. }
  107. if (fPrint)
  108. {
  109. if (fAtLeastOne)
  110. {
  111. i += wprintf(TEXT("\n"));
  112. }
  113. i += _PrintIndent(cchIndent);
  114. if (fPrintValue)
  115. {
  116. if (fHex)
  117. {
  118. i += wprintf(TEXT("0x%08X, "), rgflag[dw].dwFlag);
  119. }
  120. else
  121. {
  122. i += wprintf(TEXT("%u, "), rgflag[dw].dwFlag);
  123. }
  124. }
  125. i += wprintf(TEXT("%s"), rgflag[dw].pszDescr);
  126. if (fComment)
  127. {
  128. i += wprintf(TEXT(", '%s'"), rgflag[dw].pszComment);
  129. }
  130. fAtLeastOne = TRUE;
  131. }
  132. }
  133. return i;
  134. }
  135. HANDLE _GetDeviceHandle(LPTSTR psz, DWORD dwDesiredAccess, DWORD dwFileAttributes)
  136. {
  137. HANDLE hDevice = CreateFile(psz, // drive to open
  138. dwDesiredAccess, // don't need any access to the drive
  139. FILE_SHARE_READ | FILE_SHARE_WRITE, // share mode
  140. NULL, // default security attributes
  141. OPEN_EXISTING, // disposition
  142. dwFileAttributes, // file attributes
  143. NULL); // don't copy any file's attributes
  144. return hDevice;
  145. }