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.

192 lines
4.9 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1995 - 1998.
  5. //
  6. // File: qcanon.cxx
  7. //
  8. // Contents: CCiCanonicalOutput class
  9. //
  10. // History: 6-06-95 srikants Created
  11. //
  12. //--------------------------------------------------------------------------
  13. #include <pch.cxx>
  14. #pragma hdrstop
  15. #include <qcanon.hxx>
  16. //+---------------------------------------------------------------------------
  17. //
  18. // Function: CastToStorageVariant
  19. //
  20. // Synopsis: To treat a variant as a CStorageVariant. Because CStorageVariant
  21. // derives from PROPVARIANT in a "protected" fashion, we cannot
  22. // directly typecast a PROPVARIANT * to a CStorageVariant *
  23. //
  24. // Arguments: [varnt] - The variant that must be type casted.
  25. //
  26. // Returns: A pointer to varnt as a CStorageVariant.
  27. //
  28. // History: 6-06-95 srikants Created
  29. //
  30. // Notes: There are two overloaded implementations, one to convert
  31. // a reference to const to a pointer to const.
  32. //
  33. //----------------------------------------------------------------------------
  34. inline
  35. CStorageVariant * CastToStorageVariant( PROPVARIANT & varnt )
  36. {
  37. return (CStorageVariant *) ((void *) &varnt);
  38. }
  39. inline
  40. CStorageVariant const * CastToStorageVariant( PROPVARIANT const & varnt )
  41. {
  42. return (CStorageVariant *) ((void *) &varnt);
  43. }
  44. //+---------------------------------------------------------------------------
  45. //
  46. // Method: CCiCanonicalOutput::PutWString, static public
  47. //
  48. // Synopsis:
  49. //
  50. // Arguments: [stm] -
  51. // [pwszStr] -
  52. //
  53. // Returns:
  54. //
  55. // History: 6-21-95 srikants Created
  56. //
  57. // Notes:
  58. //
  59. //----------------------------------------------------------------------------
  60. void CCiCanonicalOutput::PutWString( PSerStream & stm, WCHAR const * pwszStr )
  61. {
  62. ULONG cwc = (0 != pwszStr) ? wcslen( pwszStr ) : 0;
  63. stm.PutULong( cwc );
  64. if (cwc)
  65. stm.PutWChar( pwszStr, cwc );
  66. }
  67. //+---------------------------------------------------------------------------
  68. //
  69. // Method: CCiCanonicalOutput::GetWString, static public
  70. //
  71. // Synopsis:
  72. //
  73. // Arguments: [stm] -
  74. // [fSuccess] -
  75. //
  76. // Returns:
  77. //
  78. // History: 6-21-95 srikants Created
  79. //
  80. // Notes:
  81. //
  82. //----------------------------------------------------------------------------
  83. WCHAR * CCiCanonicalOutput::GetWString( PDeSerStream & stm, BOOL & fSuccess )
  84. {
  85. ULONG cwc = stm.GetULong();
  86. fSuccess = TRUE;
  87. if ( 0 == cwc )
  88. {
  89. return 0;
  90. }
  91. ULONG cb = (cwc+1) * sizeof(WCHAR);
  92. WCHAR * pwszStr = (WCHAR *) CoTaskMemAlloc( cb );
  93. if ( 0 == pwszStr )
  94. {
  95. fSuccess = FALSE;
  96. return 0;
  97. }
  98. stm.GetWChar( pwszStr, cwc );
  99. pwszStr[cwc] = L'\0';
  100. return pwszStr;
  101. }
  102. //+---------------------------------------------------------------------------
  103. //
  104. // Method: CCiCanonicalOutput::AllocAndCopyWString, static public
  105. //
  106. // Synopsis:
  107. //
  108. // Arguments: [pSrc] -
  109. //
  110. // Returns:
  111. //
  112. // History: 6-22-95 srikants Created
  113. //
  114. // Notes:
  115. //
  116. //----------------------------------------------------------------------------
  117. WCHAR * CCiCanonicalOutput::AllocAndCopyWString( const WCHAR * pSrc )
  118. {
  119. WCHAR * pDst = 0;
  120. if ( 0 != pSrc )
  121. {
  122. const cb = ( wcslen( pSrc ) + 1 ) * sizeof(WCHAR);
  123. pDst = (WCHAR *) new WCHAR [ cb/sizeof(WCHAR) ];
  124. if ( 0 != pDst )
  125. {
  126. RtlCopyMemory( pDst, pSrc, cb );
  127. }
  128. }
  129. return pDst;
  130. }
  131. //+---------------------------------------------------------------------------
  132. //
  133. // Member: CCiCanonicalQueryRows::Init
  134. //
  135. // Synopsis: Initializes the query rows output structure for writing
  136. // results out.
  137. //
  138. // History: 7-01-96 srikants Created
  139. //
  140. //----------------------------------------------------------------------------
  141. void CCiCanonicalQueryRows::Init()
  142. {
  143. RtlZeroMemory( this, sizeof(CCiCanonicalQueryRows) );
  144. InitVersion();
  145. SetOutputType( CCiCanonicalOutput::eQueryRows );
  146. }
  147. //+---------------------------------------------------------------------------
  148. //
  149. // Member: CQuadByteAlignedBuffer::CQuadByteAlignedBuffer
  150. //
  151. // Synopsis: Constructor for a quad aligned buffer class.
  152. //
  153. // Arguments: [cbBuffer] - Number of bytes in the buffer class.
  154. //
  155. // History: 6-16-96 srikants Created
  156. //
  157. //----------------------------------------------------------------------------
  158. CQuadByteAlignedBuffer::CQuadByteAlignedBuffer( ULONG cbBuffer )
  159. {
  160. // allocator guarantees 8-byte alignment
  161. _pbAlloc = new BYTE [ cbBuffer ];
  162. _cbAlloc = cbBuffer;
  163. Win4Assert( ( ((ULONG_PTR) _pbAlloc) & 0x7) == 0 );
  164. _pbAligned = _pbAlloc;
  165. _cbAligned = _cbAlloc;
  166. }