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.

269 lines
5.4 KiB

  1. /******************************************************************************
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. Serializer.cpp
  5. Abstract:
  6. This file contains the implementation of various Serializer In/Out operators.
  7. Revision History:
  8. Davide Massarenti (Dmassare) 04/20/99
  9. created
  10. ******************************************************************************/
  11. #include <stdafx.h>
  12. /////////////////////////////////////////////////////////////////////////
  13. HRESULT MPC::Serializer::operator>>( /*[out]*/ MPC::string& szVal )
  14. {
  15. __MPC_FUNC_ENTRY( COMMONID, "MPC::Serializer::operator>> MPC::string" );
  16. HRESULT hr;
  17. DWORD dwSize;
  18. char rgBuf[512+1];
  19. szVal = "";
  20. __MPC_EXIT_IF_METHOD_FAILS(hr, *this >> dwSize);
  21. while(dwSize)
  22. {
  23. DWORD dwLen = min( 512 / sizeof(char), dwSize );
  24. __MPC_EXIT_IF_METHOD_FAILS(hr, read( rgBuf, dwLen * sizeof(char) ));
  25. rgBuf[dwLen] = 0;
  26. szVal += rgBuf; dwSize -= dwLen;
  27. }
  28. hr = S_OK;
  29. __MPC_FUNC_CLEANUP;
  30. __MPC_FUNC_EXIT(hr);
  31. }
  32. HRESULT MPC::Serializer::operator<<( /*[in]*/ const MPC::string& szVal )
  33. {
  34. __MPC_FUNC_ENTRY( COMMONID, "MPC::Serializer::operator<< MPC::string" );
  35. HRESULT hr;
  36. DWORD dwSize = szVal.length();
  37. __MPC_EXIT_IF_METHOD_FAILS(hr, *this << dwSize);
  38. __MPC_EXIT_IF_METHOD_FAILS(hr, write( szVal.c_str(), szVal.length() * sizeof(char) ));
  39. hr = S_OK;
  40. __MPC_FUNC_CLEANUP;
  41. __MPC_FUNC_EXIT(hr);
  42. }
  43. ////////////////////
  44. HRESULT MPC::Serializer::operator>>( /*[out]*/ MPC::wstring& szVal )
  45. {
  46. __MPC_FUNC_ENTRY( COMMONID, "MPC::Serializer::operator>> MPC::wstring" );
  47. HRESULT hr;
  48. DWORD dwSize;
  49. WCHAR rgBuf[512+1];
  50. szVal = L"";
  51. __MPC_EXIT_IF_METHOD_FAILS(hr, *this >> dwSize);
  52. while(dwSize)
  53. {
  54. DWORD dwLen = min( 512 / sizeof(WCHAR), dwSize );
  55. __MPC_EXIT_IF_METHOD_FAILS(hr, read( rgBuf, dwLen * sizeof(WCHAR) ));
  56. rgBuf[dwLen] = 0;
  57. szVal += rgBuf; dwSize -= dwLen;
  58. }
  59. hr = S_OK;
  60. __MPC_FUNC_CLEANUP;
  61. __MPC_FUNC_EXIT(hr);
  62. }
  63. HRESULT MPC::Serializer::operator<<( /*[in]*/ const MPC::wstring& szVal )
  64. {
  65. __MPC_FUNC_ENTRY( COMMONID, "MPC::Serializer::operator<< MPC::wstring" );
  66. HRESULT hr;
  67. DWORD dwSize = szVal.length();
  68. __MPC_EXIT_IF_METHOD_FAILS(hr, *this << dwSize);
  69. __MPC_EXIT_IF_METHOD_FAILS(hr, write( szVal.c_str(), szVal.length() * sizeof(WCHAR) ));
  70. hr = S_OK;
  71. __MPC_FUNC_CLEANUP;
  72. __MPC_FUNC_EXIT(hr);
  73. }
  74. ////////////////////
  75. HRESULT MPC::Serializer::operator>>( /*[out]*/ CComBSTR& bstrVal )
  76. {
  77. __MPC_FUNC_ENTRY( COMMONID, "MPC::Serializer::operator>> CComBSTR" );
  78. HRESULT hr;
  79. DWORD dwSize;
  80. bstrVal.Empty();
  81. __MPC_EXIT_IF_METHOD_FAILS(hr, *this >> dwSize);
  82. if(dwSize)
  83. {
  84. BSTR bstr;
  85. __MPC_EXIT_IF_ALLOC_FAILS(hr, bstr, ::SysAllocStringByteLen( NULL, dwSize ));
  86. bstrVal.Attach( bstr );
  87. __MPC_EXIT_IF_METHOD_FAILS(hr, read( bstrVal.m_str, dwSize ));
  88. }
  89. hr = S_OK;
  90. __MPC_FUNC_CLEANUP;
  91. __MPC_FUNC_EXIT(hr);
  92. }
  93. HRESULT MPC::Serializer::operator<<( /*[in]*/ const CComBSTR& bstrVal )
  94. {
  95. __MPC_FUNC_ENTRY( COMMONID, "MPC::Serializer::operator<< CComBSTR" );
  96. HRESULT hr;
  97. DWORD dwSize;
  98. dwSize = (bstrVal.m_str) ? ::SysStringByteLen( bstrVal.m_str ) : 0;
  99. __MPC_EXIT_IF_METHOD_FAILS(hr, *this << dwSize);
  100. __MPC_EXIT_IF_METHOD_FAILS(hr, write( bstrVal.m_str, dwSize ));
  101. hr = S_OK;
  102. __MPC_FUNC_CLEANUP;
  103. __MPC_FUNC_EXIT(hr);
  104. }
  105. ////////////////////
  106. HRESULT MPC::Serializer::operator>>( /*[out]*/ CComHGLOBAL& val )
  107. {
  108. __MPC_FUNC_ENTRY( COMMONID, "MPC::Serializer::operator>> CComHGLOBAL" );
  109. HRESULT hr;
  110. DWORD dwSize;
  111. __MPC_EXIT_IF_METHOD_FAILS(hr, *this >> dwSize);
  112. __MPC_EXIT_IF_METHOD_FAILS(hr, val.New( GMEM_FIXED, dwSize ));
  113. __MPC_EXIT_IF_METHOD_FAILS(hr, read( val.Get(), dwSize ));
  114. hr = S_OK;
  115. __MPC_FUNC_CLEANUP;
  116. __MPC_FUNC_EXIT(hr);
  117. }
  118. HRESULT MPC::Serializer::operator<<( /*[in]*/ const CComHGLOBAL& val )
  119. {
  120. __MPC_FUNC_ENTRY( COMMONID, "MPC::Serializer::operator<< CComHGLOBAL" );
  121. HRESULT hr;
  122. DWORD dwSize = val.Size();
  123. LPVOID ptr = val.Lock();
  124. __MPC_EXIT_IF_METHOD_FAILS(hr, *this << dwSize);
  125. __MPC_EXIT_IF_METHOD_FAILS(hr, write( ptr, dwSize ));
  126. hr = S_OK;
  127. __MPC_FUNC_CLEANUP;
  128. val.Unlock();
  129. __MPC_FUNC_EXIT(hr);
  130. }
  131. ////////////////////
  132. HRESULT MPC::Serializer::operator>>( /*[out]*/ CComPtr<IStream>& val )
  133. {
  134. __MPC_FUNC_ENTRY( COMMONID, "MPC::Serializer::operator>> IStream" );
  135. HRESULT hr;
  136. CComHGLOBAL chg;
  137. val.Release();
  138. __MPC_EXIT_IF_METHOD_FAILS(hr, *this >> chg);
  139. __MPC_EXIT_IF_METHOD_FAILS(hr, chg.DetachAsStream( &val ));
  140. hr = S_OK;
  141. __MPC_FUNC_CLEANUP;
  142. __MPC_FUNC_EXIT(hr);
  143. }
  144. HRESULT MPC::Serializer::operator<<( /*[in]*/ IStream* val )
  145. {
  146. __MPC_FUNC_ENTRY( COMMONID, "MPC::Serializer::operator<< IStream" );
  147. HRESULT hr;
  148. CComHGLOBAL chg;
  149. __MPC_EXIT_IF_METHOD_FAILS(hr, chg.CopyFromStream( val ));
  150. __MPC_EXIT_IF_METHOD_FAILS(hr, *this << chg);
  151. hr = S_OK;
  152. __MPC_FUNC_CLEANUP;
  153. __MPC_FUNC_EXIT(hr);
  154. }