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.

139 lines
2.7 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1992.
  5. //
  6. // File: MemSer.cxx
  7. //
  8. // History: 29-Jul-94 KyleP Created
  9. //
  10. //--------------------------------------------------------------------------
  11. #include <pch.cxx>
  12. #pragma hdrstop
  13. #include <qmemser.hxx>
  14. CQMemSerStream::CQMemSerStream( unsigned cb )
  15. : _cb( cb )
  16. {
  17. _pb = (BYTE *) GlobalAlloc( GPTR | GMEM_DDESHARE, cb );
  18. if ( _pb == 0 )
  19. THROW ( CException( E_OUTOFMEMORY ) );
  20. _pbCurrent = _pb;
  21. }
  22. CQMemSerStream::CQMemSerStream( BYTE * pb )
  23. : _cb( 0 ),
  24. _pb( pb ),
  25. _pbCurrent( _pb )
  26. {
  27. }
  28. CQMemSerStream::~CQMemSerStream()
  29. {
  30. if ( _cb > 0 )
  31. GlobalFree( _pb );
  32. }
  33. BYTE *CQMemSerStream::AcqBuf()
  34. {
  35. BYTE *pTmp = _pb;
  36. _pb = 0;
  37. _cb = 0;
  38. return (pTmp) ;
  39. }
  40. void CQMemSerStream::PutByte( BYTE b )
  41. {
  42. *_pbCurrent = b;
  43. _pbCurrent += 1;
  44. }
  45. void CQMemSerStream::PutChar( char const * pc, ULONG cc )
  46. {
  47. memcpy( _pbCurrent, pc, cc );
  48. _pbCurrent += cc;
  49. }
  50. void CQMemSerStream::PutWChar( WCHAR const * pwc, ULONG cc )
  51. {
  52. WCHAR * pwcTemp = AlignWCHAR(_pbCurrent);
  53. memcpy( pwcTemp, pwc, cc * sizeof(WCHAR) );
  54. _pbCurrent = (BYTE *)(pwcTemp + cc);
  55. }
  56. void CQMemSerStream::PutUShort( USHORT us )
  57. {
  58. USHORT * pus = AlignUSHORT(_pbCurrent);
  59. *pus = us;
  60. _pbCurrent = (BYTE *)(pus + 1);
  61. }
  62. void CQMemSerStream::PutULong( ULONG ul )
  63. {
  64. ULONG * pul = AlignULONG(_pbCurrent);
  65. *pul = ul;
  66. _pbCurrent = (BYTE *)(pul + 1);
  67. }
  68. void CQMemSerStream::PutLong( long l )
  69. {
  70. long * pl = AlignLong(_pbCurrent);
  71. *pl = l;
  72. _pbCurrent = (BYTE *)(pl + 1);
  73. }
  74. void CQMemSerStream::PutFloat( float f )
  75. {
  76. float * pf = AlignFloat(_pbCurrent);
  77. *pf = f;
  78. _pbCurrent = (BYTE *)(pf + 1);
  79. }
  80. void CQMemSerStream::PutDouble( double d )
  81. {
  82. double * pd = AlignDouble(_pbCurrent);
  83. *pd = d;
  84. _pbCurrent = (BYTE *)(pd + 1);
  85. }
  86. void CQMemSerStream::PutString( char const * psz )
  87. {
  88. ULONG len = strlen(psz);
  89. ULONG * pul = AlignULONG(_pbCurrent);
  90. *pul = len;
  91. _pbCurrent = (BYTE *)(pul + 1);
  92. memcpy(_pbCurrent, psz, len);
  93. _pbCurrent += len;
  94. }
  95. void CQMemSerStream::PutWString( WCHAR const * pwsz )
  96. {
  97. ULONG len = wcslen(pwsz);
  98. ULONG * pul = AlignULONG(_pbCurrent);
  99. *pul = len;
  100. len *= sizeof(WCHAR);
  101. _pbCurrent = (BYTE *)(pul + 1);
  102. memcpy(_pbCurrent, pwsz, len );
  103. _pbCurrent += len;
  104. }
  105. void CQMemSerStream::PutBlob( BYTE const * pb, ULONG cb )
  106. {
  107. memcpy( _pbCurrent, pb, cb );
  108. _pbCurrent += cb;
  109. }
  110. void CQMemSerStream::PutGUID( GUID const & guid )
  111. {
  112. GUID * pguid = (GUID *)AlignGUID(_pbCurrent);
  113. memcpy( pguid, &guid, sizeof(guid) );
  114. _pbCurrent = (BYTE *)(pguid + 1);
  115. }