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.

254 lines
6.9 KiB

  1. /*++
  2. Copyright (c) 1997-1999 Microsoft Corporation
  3. Module Name:
  4. dspdatadlg.c
  5. Abstract:
  6. Author:
  7. 16-Jan-1997 AlanWar
  8. Revision History:
  9. --*/
  10. // DisplayDataDlg.cpp : implementation file
  11. //
  12. #include "stdafx.h"
  13. #include "EnumGuid.h"
  14. #include "DspDataDlg.h"
  15. #ifdef _DEBUG
  16. #define new DEBUG_NEW
  17. #undef THIS_FILE
  18. static char THIS_FILE[] = __FILE__;
  19. #endif
  20. /////////////////////////////////////////////////////////////////////////////
  21. // CDisplayDataDlg dialog
  22. #include "wmihlp.h"
  23. CDisplayDataDlg::CDisplayDataDlg(PWNODE_ALL_DATA pwNode,
  24. CWnd* pParent /*=NULL*/)
  25. : CDialog(CDisplayDataDlg::IDD, pParent), pwNode(pwNode), pwSingleNode(0)
  26. {
  27. //{{AFX_DATA_INIT(CDisplayDataDlg)
  28. // NOTE: the ClassWizard will add member initialization here
  29. //}}AFX_DATA_INIT
  30. }
  31. CDisplayDataDlg::CDisplayDataDlg(PWNODE_SINGLE_INSTANCE pwNode,
  32. CWnd* pParent /*=NULL*/)
  33. : CDialog(CDisplayDataDlg::IDD, pParent), pwNode(0),
  34. pwSingleNode(pwNode) {}
  35. void CDisplayDataDlg::DoDataExchange(CDataExchange* pDX)
  36. {
  37. CDialog::DoDataExchange(pDX);
  38. //{{AFX_DATA_MAP(CDisplayDataDlg)
  39. DDX_Control(pDX, IDC_DATA, txtData);
  40. //}}AFX_DATA_MAP
  41. }
  42. BEGIN_MESSAGE_MAP(CDisplayDataDlg, CDialog)
  43. //{{AFX_MSG_MAP(CDisplayDataDlg)
  44. //}}AFX_MSG_MAP
  45. END_MESSAGE_MAP()
  46. /////////////////////////////////////////////////////////////////////////////
  47. // CDisplayDataDlg message handlers
  48. BOOL CDisplayDataDlg::OnInitDialog()
  49. {
  50. CDialog::OnInitDialog();
  51. if (pwNode)
  52. DisplayAllData(pwNode);
  53. else if (pwSingleNode)
  54. DisplaySingleInstance(pwSingleNode);
  55. return TRUE; // return TRUE unless you set the focus to a control
  56. // EXCEPTION: OCX Property Pages should return FALSE
  57. }
  58. void CDisplayDataDlg::DisplayAllData(PWNODE_ALL_DATA Wnode)
  59. {
  60. DWORD dwInstanceNum;
  61. DWORD dwByteCount;
  62. DWORD dwFlags;
  63. DWORD dwStructureNum = 1;
  64. DWORD dwTemp;
  65. DWORD dwInstanceSize;
  66. LPDWORD lpdwNameOffsets;
  67. PBYTE lpbyteData;
  68. BOOL bFixedSize = FALSE;
  69. CString output, tmp;
  70. do {
  71. tmp.Format(_T("\r\nWNODE_ALL_DATA structure %d.\r\n"), dwStructureNum++);
  72. output += tmp;
  73. PrintHeader(Wnode->WnodeHeader, output);
  74. dwFlags = Wnode->WnodeHeader.Flags;
  75. if ( ! (dwFlags & WNODE_FLAG_ALL_DATA)) {
  76. txtData.SetWindowText(_T("Not a WNODE_ALL_DATA structure\r\n"));
  77. return;
  78. }
  79. // Check for fixed instance size
  80. //
  81. bFixedSize = FALSE;
  82. if ( dwFlags & WNODE_FLAG_FIXED_INSTANCE_SIZE ) {
  83. dwInstanceSize = Wnode->FixedInstanceSize;
  84. bFixedSize = TRUE;
  85. lpbyteData = OffsetToPtr((PBYTE)Wnode, Wnode->DataBlockOffset);
  86. tmp.Format(_T("Fixed size: 0x%x\r\n"), dwInstanceSize);
  87. output += tmp;
  88. }
  89. // Get a pointer to the array of offsets to the instance names
  90. //
  91. lpdwNameOffsets = (LPDWORD) OffsetToPtr(Wnode, Wnode->OffsetInstanceNameOffsets);
  92. // Print out each instance name and data. The name will always be
  93. // in UNICODE so it needs to be translated to ASCII before it can be
  94. // printed out.
  95. //
  96. for ( dwInstanceNum = 0; dwInstanceNum < Wnode->InstanceCount; dwInstanceNum++) {
  97. tmp.Format(_T("Instance %d\r\n"), 1 + dwInstanceNum);
  98. output += tmp;
  99. PrintCountedString( (LPTSTR)
  100. OffsetToPtr( Wnode,
  101. lpdwNameOffsets[dwInstanceNum]),
  102. output);
  103. // Length and offset for variable data
  104. //
  105. if ( !bFixedSize) {
  106. dwInstanceSize = Wnode->OffsetInstanceDataAndLength[dwInstanceNum].
  107. LengthInstanceData;
  108. tmp.Format(_T("Data size 0x%x\r\n"), dwInstanceSize);
  109. output += tmp;
  110. lpbyteData = (PBYTE) OffsetToPtr((PBYTE)Wnode,
  111. Wnode->OffsetInstanceDataAndLength[dwInstanceNum].
  112. OffsetInstanceData);
  113. }
  114. output += _T(" Data:");
  115. for ( dwByteCount = 0; dwByteCount < dwInstanceSize; ) {
  116. // Print data in groups of DWORDS but allow for single bytes.
  117. //
  118. if ( (dwByteCount % 16) == 0) {
  119. output += _T("\r\n");
  120. }
  121. if ( (dwByteCount % 4) == 0) {
  122. output += _T(" "); // _T(" 0x");
  123. }
  124. dwTemp = *((LPDWORD)lpbyteData);
  125. tmp.Format(_T("%.8x"), dwTemp );
  126. output += tmp;
  127. lpbyteData += sizeof(DWORD);
  128. dwByteCount += sizeof(DWORD);
  129. } // for cByteCount
  130. output += _T("\r\n\r\n");
  131. } // for cInstanceNum
  132. // Update Wnode to point to next node
  133. //
  134. if ( Wnode->WnodeHeader.Linkage != 0) {
  135. Wnode = (PWNODE_ALL_DATA) OffsetToPtr( Wnode, Wnode->WnodeHeader.Linkage);
  136. }
  137. else {
  138. Wnode = 0;
  139. }
  140. } while(Wnode != 0);
  141. txtData.SetWindowText(output);
  142. }
  143. void CDisplayDataDlg::DisplaySingleInstance(PWNODE_SINGLE_INSTANCE Wnode)
  144. {
  145. DWORD dwByteCount;
  146. DWORD dwFlags;
  147. LPDWORD lpdwData;
  148. USHORT usNameLength;
  149. CString tmp, output;
  150. dwFlags = Wnode->WnodeHeader.Flags;
  151. if ( ! (dwFlags & WNODE_FLAG_SINGLE_INSTANCE)) {
  152. txtData.SetWindowText(_T("Not a WNODE_SINGLE_INSTANCE structure"));
  153. return;
  154. }
  155. output = _T("WNODE_SINGLE_INSTANCE.\r\n");
  156. PrintHeader(Wnode->WnodeHeader, output);
  157. // Print name or index number
  158. //
  159. if ( dwFlags & WNODE_FLAG_STATIC_INSTANCE_NAMES ) {
  160. tmp.Format(_T("Instance index: %d\r\n"), Wnode->InstanceIndex);
  161. output += tmp;
  162. }
  163. usNameLength = * (USHORT *) OffsetToPtr(Wnode, Wnode->OffsetInstanceName);
  164. tmp.Format(_T("Name length 0x%x\r\n"), usNameLength);
  165. output += tmp;
  166. usNameLength /= 2;
  167. PrintCountedString( (LPTSTR) OffsetToPtr( Wnode,
  168. Wnode->OffsetInstanceName), output );
  169. // wcscpy(lpNameW, (LPWSTR) (OffsetToPtr(Wnode, Wnode->OffsetInstanceName )
  170. // + sizeof(USHORT)));
  171. // wcsncpy( lpNameW + usNameLength, L" ", 2);
  172. // wcstombs( lpName, lpNameW, 300);
  173. // printf("%s\r\n", lpName);
  174. // Print out the Data
  175. //
  176. tmp.Format(_T(" Data:\r\nData Size: 0x%x\r\n"), Wnode->SizeDataBlock);
  177. output += tmp;
  178. lpdwData = (PULONG) OffsetToPtr(Wnode, Wnode->DataBlockOffset);
  179. for ( dwByteCount = 0; dwByteCount < Wnode->SizeDataBlock; dwByteCount+= sizeof(ULONG)) {
  180. if ( (dwByteCount % 16) == 0) {
  181. output += _T("\r\n");
  182. }
  183. tmp.Format(_T("0x%.8x "), *lpdwData);
  184. output += tmp;
  185. lpdwData++;
  186. }
  187. txtData.SetWindowText(output);
  188. }