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.

76 lines
2.0 KiB

  1. // Persist.cpp : Implementation of persistence
  2. #include "stdafx.h"
  3. #include "compdata.h"
  4. #include "safetemp.h"
  5. #include "macros.h"
  6. USE_HANDLE_MACROS("SCHMMGMT(persist.cpp)")
  7. STDMETHODIMP ComponentData::Load(IStream __RPC_FAR *pIStream)
  8. {
  9. MFC_TRY;
  10. #ifndef DONT_PERSIST
  11. ASSERT( NULL != pIStream );
  12. XSafeInterfacePtr<IStream> pIStreamSafePtr( pIStream );
  13. // read server name from stream
  14. DWORD dwLen = 0;
  15. HRESULT hr = pIStream->Read( &dwLen, 4, NULL );
  16. if ( FAILED(hr) )
  17. {
  18. ASSERT( FALSE );
  19. return hr;
  20. }
  21. ASSERT( dwLen <= MAX_PATH*sizeof(WCHAR) );
  22. LPCWSTR lpwcszMachineName = (LPCWSTR)alloca( dwLen );
  23. // allocated from stack, we don't need to free
  24. if (NULL == lpwcszMachineName)
  25. {
  26. AfxThrowMemoryException();
  27. return E_OUTOFMEMORY;
  28. }
  29. hr = pIStream->Read( (PVOID)lpwcszMachineName, dwLen, NULL );
  30. if ( FAILED(hr) )
  31. {
  32. ASSERT( FALSE );
  33. return hr;
  34. }
  35. QueryRootCookie().SetMachineName( lpwcszMachineName );
  36. #endif
  37. return S_OK;
  38. MFC_CATCH;
  39. }
  40. STDMETHODIMP ComponentData::Save(IStream __RPC_FAR *pIStream, BOOL)
  41. {
  42. MFC_TRY;
  43. #ifndef DONT_PERSIST
  44. ASSERT( NULL != pIStream );
  45. XSafeInterfacePtr<IStream> pIStreamSafePtr( pIStream );
  46. LPCWSTR lpwcszMachineName = QueryRootCookie().QueryNonNULLMachineName();
  47. DWORD dwLen = static_cast<DWORD>((::wcslen(lpwcszMachineName)+1)*sizeof(WCHAR));
  48. ASSERT( 4 == sizeof(DWORD) );
  49. HRESULT hr = pIStream->Write( &dwLen, 4, NULL );
  50. if ( FAILED(hr) )
  51. {
  52. ASSERT( FALSE );
  53. return hr;
  54. }
  55. hr = pIStream->Write( lpwcszMachineName, dwLen, NULL );
  56. if ( FAILED(hr) )
  57. {
  58. ASSERT( FALSE );
  59. return hr;
  60. }
  61. #endif
  62. return S_OK;
  63. MFC_CATCH;
  64. }