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.

201 lines
5.0 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 2002.
  5. //
  6. // File: pidmap.cxx
  7. //
  8. // Contents: Maps pid <--> property name.
  9. //
  10. // History: 31-Jan-93 KyleP Created
  11. //
  12. //--------------------------------------------------------------------------
  13. #include <pch.cxx>
  14. #pragma hdrstop
  15. #include <pidmap.hxx>
  16. #include <coldesc.hxx>
  17. IMPL_DYNARRAY( CPropNameArrayBase, CFullPropSpec );
  18. //+-------------------------------------------------------------------------
  19. //--------------------------------------------------------------------------
  20. CPropNameArray::CPropNameArray(unsigned size)
  21. : CPropNameArrayBase( size )
  22. {
  23. }
  24. //+-------------------------------------------------------------------------
  25. //--------------------------------------------------------------------------
  26. void CPropNameArray::Marshall( PSerStream & stm ) const
  27. {
  28. //
  29. // Compute # non-zero items
  30. //
  31. for ( unsigned len = 0; len < Size(); len++ )
  32. {
  33. if ( 0 == Get(len) )
  34. break;
  35. }
  36. stm.PutULong( len );
  37. for ( unsigned i = 0; i < len; i++ )
  38. {
  39. Get(i)->Marshall( stm );
  40. }
  41. }
  42. //+-------------------------------------------------------------------------
  43. //--------------------------------------------------------------------------
  44. CPropNameArray::CPropNameArray( PDeSerStream & stm )
  45. : CPropNameArrayBase( 0 )
  46. {
  47. ULONG cItems = stm.GetULong();
  48. // Guard against attack
  49. if ( 0 == cItems || cItems > 1000 )
  50. THROW( CException( E_INVALIDARG ) );
  51. SetExactSize( cItems );
  52. for ( unsigned i = 0; i < cItems; i++ )
  53. {
  54. CFullPropSpec * pps = new CFullPropSpec( stm );
  55. XPtr<CFullPropSpec> xpps(pps);
  56. if ( xpps.IsNull() || !xpps->IsValid() )
  57. {
  58. THROW( CException( STATUS_NO_MEMORY ) );
  59. }
  60. Add( pps, i);
  61. xpps.Acquire();
  62. }
  63. }
  64. //+-------------------------------------------------------------------------
  65. //
  66. // Member: CPidMapper::NameToPid, public
  67. //
  68. // Arguments: [wcsProperty] -- Property name
  69. //
  70. // Returns: 'fake' (pid) for [wcsProperty].
  71. //
  72. // History: 31-Jan-93 KyleP Created
  73. //
  74. //--------------------------------------------------------------------------
  75. PROPID CPidMapper::NameToPid( CFullPropSpec const & Property )
  76. {
  77. if ( !Property.IsValid() )
  78. return pidInvalid;
  79. //
  80. // Just linear search the array. It should be small.
  81. //
  82. for ( int i = Count() - 1; i >= 0; i-- )
  83. {
  84. Win4Assert( Get(i) != 0 );
  85. if ( *Get( i ) == Property )
  86. {
  87. return( i );
  88. }
  89. }
  90. //
  91. // Wasn't in array. Add.
  92. //
  93. CFullPropSpec * ppsFull = new CFullPropSpec( Property );
  94. XPtr<CFullPropSpec> xpps(ppsFull);
  95. if ( xpps.IsNull() || !xpps->IsValid() )
  96. {
  97. THROW( CException( STATUS_NO_MEMORY ) );
  98. }
  99. PROPID pidNew = Count();
  100. Add( ppsFull, pidNew );
  101. xpps.Acquire();
  102. _apidReal[pidNew] = pidInvalid;
  103. return pidNew;
  104. }
  105. //+-------------------------------------------------------------------------
  106. //
  107. // Member: CPidMapper::PidToRealPid, public
  108. //
  109. // Synopsis: Converts a fake (index) pid to real pid.
  110. //
  111. // Arguments: [pidFake] -- Fake (index) pid
  112. //
  113. // Returns: Real pid
  114. //
  115. // History: 30-Dec-1997 KyleP Created
  116. //
  117. //--------------------------------------------------------------------------
  118. PROPID CPidMapper::PidToRealPid( PROPID pidFake )
  119. {
  120. if ( pidInvalid == _apidReal[pidFake] )
  121. {
  122. Win4Assert( 0 != _pPidConverter );
  123. SCODE sc = _pPidConverter->FPSToPROPID( *Get(pidFake), _apidReal[pidFake] );
  124. if ( FAILED(sc) )
  125. {
  126. THROW( CException( sc ) );
  127. }
  128. #if CIDBG == 1
  129. if ( vqInfoLevel & DEB_ITRACE )
  130. {
  131. CFullPropSpec const & ps = *Get(pidFake);
  132. GUID const & guid = ps.GetPropSet();
  133. char szGuid[50];
  134. sprintf( szGuid,
  135. "%08lX-%04X-%04X-%02X%02X%02X%02X%02X%02X%02X%02X\\",
  136. guid.Data1,
  137. guid.Data2,
  138. guid.Data3,
  139. guid.Data4[0], guid.Data4[1],
  140. guid.Data4[2], guid.Data4[3],
  141. guid.Data4[4], guid.Data4[5],
  142. guid.Data4[6], guid.Data4[7] );
  143. vqDebugOut(( DEB_ITRACE, szGuid ));
  144. if ( ps.IsPropertyName() )
  145. vqDebugOut(( DEB_ITRACE | DEB_NOCOMPNAME,
  146. "%ws ",
  147. ps.GetPropertyName() ));
  148. else
  149. vqDebugOut(( DEB_ITRACE | DEB_NOCOMPNAME,
  150. "0x%x ",
  151. ps.GetPropertyPropid() ));
  152. vqDebugOut(( DEB_ITRACE | DEB_NOCOMPNAME, " --> pid 0x%x\n",
  153. _apidReal[pidFake] ));
  154. }
  155. #endif // CIDBG == 1
  156. }
  157. return _apidReal[pidFake];
  158. }