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.

67 lines
2.3 KiB

  1. // Copyright (c) 2000 Microsoft Corporation. All rights reserved.
  2. //
  3. // Helpers for implementation of ISpecifyPropertyPages and IPersistStream
  4. //
  5. #pragma once
  6. #include "ocidl.h"
  7. // Paste these declarations into your class methods to implement the interfaces. Replace DSFXZZZ with the name of your struct.
  8. // These assume that you implement GetAllParameters/SetAllParameters interfaces with a struct and that you have a public m_fDirty
  9. // member variable that you use to hold the dirty state of your object for persistence.
  10. /*
  11. // ISpecifyPropertyPages
  12. STDMETHOD(GetPages)(CAUUID * pPages) { return PropertyHelp::GetPages(CLSID_DirectSoundPropZZZ, pPages); }
  13. // IPersistStream
  14. STDMETHOD(IsDirty)(void) { return m_fDirty ? S_OK : S_FALSE; }
  15. STDMETHOD(Load)(IStream *pStm) { return PropertyHelp::Load(this, DSFXZZZ(), pStm); }
  16. STDMETHOD(Save)(IStream *pStm, BOOL fClearDirty) { return PropertyHelp::Save(this, DSFXZZZ(), pStm, fClearDirty); }
  17. STDMETHOD(GetSizeMax)(ULARGE_INTEGER *pcbSize) { if (!pcbSize) return E_POINTER; pcbSize->QuadPart = sizeof(DSFXZZZ); return S_OK; }
  18. */
  19. // Load, Save, and GetPages are actually implemented in the following functions.
  20. namespace PropertyHelp
  21. {
  22. HRESULT GetPages(const CLSID &rclsidPropertyPage, CAUUID * pPages);
  23. template<class O, class S> HRESULT Load(O *pt_object, S &t_struct, IStream *pStm)
  24. {
  25. ULONG cbRead;
  26. HRESULT hr;
  27. if (pStm==NULL)
  28. return E_POINTER;
  29. hr = pStm->Read(&t_struct, sizeof(t_struct), &cbRead);
  30. if (hr != S_OK || cbRead < sizeof(t_struct))
  31. return E_FAIL;
  32. hr = pt_object->SetAllParameters(&t_struct);
  33. pt_object->m_fDirty = false;
  34. return hr;
  35. }
  36. template<class O, class S> HRESULT Save(O *pt_object, S &t_struct, IStream *pStm, BOOL fClearDirty)
  37. {
  38. HRESULT hr;
  39. if (pStm==NULL)
  40. return E_POINTER;
  41. hr = pt_object->GetAllParameters(&t_struct);
  42. if (FAILED(hr))
  43. return hr;
  44. ULONG cbWritten;
  45. hr = pStm->Write(&t_struct, sizeof(t_struct), &cbWritten);
  46. if (hr != S_OK || cbWritten < sizeof(t_struct))
  47. return E_FAIL;
  48. if (fClearDirty)
  49. pt_object->m_fDirty = false;
  50. return S_OK;
  51. }
  52. };