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.

189 lines
3.8 KiB

  1. /*++
  2. Copyright (C) 1996-1999 Microsoft Corporation
  3. Module Name:
  4. iperstmi.cpp
  5. Abstract:
  6. Implementation of the IPersistStreamInit interface exposed on the
  7. Polyline object.
  8. --*/
  9. #include "polyline.h"
  10. #include "unkhlpr.h"
  11. /*
  12. * CImpIPersistStreamInit interface implementation
  13. */
  14. IMPLEMENT_CONTAINED_INTERFACE(CPolyline, CImpIPersistStreamInit)
  15. /*
  16. * CImpIPersistStreamInit::GetClassID
  17. *
  18. * Purpose:
  19. * Returns the CLSID of the object represented by this interface.
  20. *
  21. * Parameters:
  22. * pClsID LPCLSID in which to store our CLSID.
  23. */
  24. STDMETHODIMP CImpIPersistStreamInit::GetClassID(LPCLSID pClsID)
  25. {
  26. *pClsID=m_pObj->m_clsID;
  27. return NOERROR;
  28. }
  29. /*
  30. * CImpIPersistStreamInit::IsDirty
  31. *
  32. * Purpose:
  33. * Tells the caller if we have made changes to this object since
  34. * it was loaded or initialized new.
  35. *
  36. * Parameters:
  37. * None
  38. *
  39. * Return Value:
  40. * HRESULT Contains S_OK if we ARE dirty, S_FALSE if
  41. * NOT dirty.
  42. */
  43. STDMETHODIMP CImpIPersistStreamInit::IsDirty(void)
  44. {
  45. return ResultFromScode(m_pObj->m_fDirty ? S_OK : S_FALSE);
  46. }
  47. /*
  48. * CImpIPersistStreamInit::Load
  49. *
  50. * Purpose:
  51. * Instructs the object to load itself from a previously saved
  52. * IStreamInit that was handled by Save in another object lifetime.
  53. * The seek pointer in this stream will be exactly the same as
  54. * it was when Save was called, and this function must leave
  55. * the seek pointer the same as it was on exit from Save, regardless
  56. * of success or failure. This function should not hold on to
  57. * pIStream.
  58. *
  59. * This function is called in lieu of IPersistStreamInit::InitNew
  60. * when the object already has a persistent state.
  61. *
  62. * Parameters:
  63. * pIStream LPSTREAM from which to load.
  64. */
  65. STDMETHODIMP CImpIPersistStreamInit::Load(LPSTREAM pIStream)
  66. {
  67. HRESULT hr;
  68. if (NULL==pIStream)
  69. return ResultFromScode(E_POINTER);
  70. //Read all the data into the control structure.
  71. hr = m_pObj->m_pCtrl->LoadFromStream(pIStream);
  72. return hr;
  73. }
  74. /*
  75. * CImpIPersistStreamInit::Save
  76. *
  77. * Purpose:
  78. * Saves the data for this object to an IStreamInit. Be sure not
  79. * to change the position of the seek pointer on entry to this
  80. * function: the caller will assume that you write from the
  81. * current offset. Leave the stream's seek pointer at the end
  82. * of the data written on exit.
  83. *
  84. * Parameters:
  85. * pIStream LPSTREAM in which to save our data.
  86. * fClearDirty BOOL indicating if this call should clear
  87. * the object's dirty flag (TRUE) or leave it
  88. * unchanged (FALSE).
  89. */
  90. STDMETHODIMP CImpIPersistStreamInit::Save(LPSTREAM pIStream
  91. , BOOL fClearDirty)
  92. {
  93. HRESULT hr;
  94. if (NULL==pIStream)
  95. return ResultFromScode(E_POINTER);
  96. hr = m_pObj->m_pCtrl->SaveToStream(pIStream);
  97. if (FAILED(hr))
  98. return hr;
  99. if (fClearDirty)
  100. m_pObj->m_fDirty=FALSE;
  101. return NOERROR;
  102. }
  103. /*
  104. * CImpIPersistStreamInit::GetSizeMax
  105. *
  106. * Purpose:
  107. * Returns the size of the data we would write if Save was
  108. * called right now.
  109. *
  110. * Parameters:
  111. * pcbSize ULARGE_INTEGER * in which to save the size
  112. * of the stream an immediate call to Save would
  113. * write.
  114. */
  115. STDMETHODIMP CImpIPersistStreamInit::GetSizeMax(ULARGE_INTEGER
  116. *pcbSize)
  117. {
  118. if (NULL==pcbSize)
  119. return ResultFromScode(E_POINTER);
  120. return ResultFromScode(E_UNEXPECTED);
  121. }
  122. /*
  123. * CImpIPersistStreamInit::InitNew
  124. *
  125. * Purpose:
  126. * Informs the object that it is being created new instead of
  127. * loaded from a persistent state. This will be called in lieu
  128. * of IPersistStreamInit::Load.
  129. *
  130. * Parameters:
  131. * None
  132. */
  133. STDMETHODIMP CImpIPersistStreamInit::InitNew(void)
  134. {
  135. //Nothing for us to do
  136. return NOERROR;
  137. }