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.

200 lines
4.2 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(
  25. OUT LPCLSID pClsID
  26. )
  27. {
  28. HRESULT hr = S_OK;
  29. if (pClsID == NULL) {
  30. return E_POINTER;
  31. }
  32. try {
  33. *pClsID=m_pObj->m_clsID;
  34. } catch (...) {
  35. hr = E_POINTER;
  36. }
  37. return hr;
  38. }
  39. /*
  40. * CImpIPersistStreamInit::IsDirty
  41. *
  42. * Purpose:
  43. * Tells the caller if we have made changes to this object since
  44. * it was loaded or initialized new.
  45. *
  46. * Parameters:
  47. * None
  48. *
  49. * Return Value:
  50. * HRESULT Contains S_OK if we ARE dirty, S_FALSE if
  51. * NOT dirty.
  52. */
  53. STDMETHODIMP CImpIPersistStreamInit::IsDirty(void)
  54. {
  55. return (m_pObj->m_fDirty ? S_OK : S_FALSE);
  56. }
  57. /*
  58. * CImpIPersistStreamInit::Load
  59. *
  60. * Purpose:
  61. * Instructs the object to load itself from a previously saved
  62. * IStreamInit that was handled by Save in another object lifetime.
  63. * The seek pointer in this stream will be exactly the same as
  64. * it was when Save was called, and this function must leave
  65. * the seek pointer the same as it was on exit from Save, regardless
  66. * of success or failure. This function should not hold on to
  67. * pIStream.
  68. *
  69. * This function is called in lieu of IPersistStreamInit::InitNew
  70. * when the object already has a persistent state.
  71. *
  72. * Parameters:
  73. * pIStream LPSTREAM from which to load.
  74. */
  75. STDMETHODIMP CImpIPersistStreamInit::Load(
  76. IN LPSTREAM pIStream
  77. )
  78. {
  79. HRESULT hr = S_OK;
  80. if (NULL == pIStream) {
  81. return (E_POINTER);
  82. }
  83. try {
  84. //Read all the data into the control structure.
  85. hr = m_pObj->m_pCtrl->LoadFromStream(pIStream);
  86. } catch (...) {
  87. hr = E_POINTER;
  88. }
  89. return hr;
  90. }
  91. /*
  92. * CImpIPersistStreamInit::Save
  93. *
  94. * Purpose:
  95. * Saves the data for this object to an IStreamInit. Be sure not
  96. * to change the position of the seek pointer on entry to this
  97. * function: the caller will assume that you write from the
  98. * current offset. Leave the stream's seek pointer at the end
  99. * of the data written on exit.
  100. *
  101. * Parameters:
  102. * pIStream LPSTREAM in which to save our data.
  103. * fClearDirty BOOL indicating if this call should clear
  104. * the object's dirty flag (TRUE) or leave it
  105. * unchanged (FALSE).
  106. */
  107. STDMETHODIMP CImpIPersistStreamInit::Save(
  108. IN LPSTREAM pIStream,
  109. IN BOOL fClearDirty
  110. )
  111. {
  112. HRESULT hr = S_OK;
  113. if (NULL == pIStream) {
  114. return (E_POINTER);
  115. }
  116. try {
  117. hr = m_pObj->m_pCtrl->SaveToStream(pIStream);
  118. } catch (...) {
  119. hr = E_POINTER;
  120. }
  121. if (SUCCEEDED(hr)) {
  122. if (fClearDirty)
  123. m_pObj->m_fDirty=FALSE;
  124. }
  125. return hr;
  126. }
  127. /*
  128. * CImpIPersistStreamInit::GetSizeMax
  129. *
  130. * Purpose:
  131. * Returns the size of the data we would write if Save was
  132. * called right now.
  133. *
  134. * Parameters:
  135. * pcbSize ULARGE_INTEGER * in which to save the size
  136. * of the stream an immediate call to Save would
  137. * write.
  138. */
  139. STDMETHODIMP CImpIPersistStreamInit::GetSizeMax(
  140. ULARGE_INTEGER *pcbSize
  141. )
  142. {
  143. if (NULL==pcbSize)
  144. return (E_POINTER);
  145. return (E_NOTIMPL);
  146. }
  147. /*
  148. * CImpIPersistStreamInit::InitNew
  149. *
  150. * Purpose:
  151. * Informs the object that it is being created new instead of
  152. * loaded from a persistent state. This will be called in lieu
  153. * of IPersistStreamInit::Load.
  154. *
  155. * Parameters:
  156. * None
  157. */
  158. STDMETHODIMP CImpIPersistStreamInit::InitNew(void)
  159. {
  160. //Nothing for us to do
  161. return NOERROR;
  162. }