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.

259 lines
5.4 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. faxconmenu.cpp
  5. Abstract:
  6. This file contains my implementation of IExtendContextMenu.
  7. Environment:
  8. WIN32 User Mode
  9. Author:
  10. Darwin Ouyang (t-darouy) 30-Sept-1997
  11. --*/
  12. #include "stdafx.h"
  13. #include "faxsnapin.h"
  14. #include "faxpersist.h"
  15. #include "faxadmin.h"
  16. #include "faxcomp.h"
  17. #include "faxcompd.h"
  18. #include "faxdataobj.h"
  19. #include "faxhelper.h"
  20. #include "faxstrt.h"
  21. #include "iroot.h"
  22. #pragma hdrstop
  23. HRESULT
  24. STDMETHODCALLTYPE
  25. CFaxPersistStream::GetClassID(
  26. OUT CLSID __RPC_FAR *pClassID)
  27. /*++
  28. Routine Description:
  29. This routine returns the CLSID of the snapin.
  30. Arguments:
  31. pClassID - returns the class id
  32. Return Value:
  33. HRESULT indicating SUCCEEDED() or FAILED()
  34. --*/
  35. {
  36. DebugPrint(( TEXT("Trace: CFaxPersistStream::GetClassID") ));
  37. assert( pClassID != NULL );
  38. if (!pClassID) {
  39. return E_FAIL;
  40. }
  41. *pClassID = CLSID_FaxSnapin;
  42. return S_OK;
  43. }
  44. HRESULT
  45. STDMETHODCALLTYPE
  46. CFaxPersistStream::IsDirty(
  47. void )
  48. /*++
  49. Routine Description:
  50. Returns S_OK if the stream is dirty and needs to be written out.
  51. Returns S_FALSE otherwise.
  52. Arguments:
  53. None.
  54. Return Value:
  55. HRESULT indicating if the stream is dirty.
  56. --*/
  57. {
  58. DebugPrint(( TEXT("Trace: CFaxPersistStream::IsDirty") ));
  59. if( m_bDirtyFlag == FALSE ) {
  60. return S_FALSE;
  61. } else {
  62. return S_OK; // save us
  63. }
  64. }
  65. HRESULT
  66. STDMETHODCALLTYPE
  67. CFaxPersistStream::Load(
  68. /* [unique] */ IN IStream __RPC_FAR *pStm)
  69. /*++
  70. Routine Description:
  71. Loads the state of the snapin from the stream in pStm
  72. Arguments:
  73. pStm - stream to read snapin state from
  74. Return Value:
  75. HRESULT indicating SUCCEEDED() or FAILED()
  76. --*/
  77. {
  78. DebugPrint(( TEXT("Trace: CFaxPersistStream::Load") ));
  79. assert( pStm != NULL );
  80. assert( m_pFaxSnapin != NULL );
  81. HRESULT hr;
  82. int iResult;
  83. BOOL isremote;
  84. ULONG count;
  85. TCHAR machineName[ MAX_COMPUTERNAME_LENGTH + 1 ];
  86. do {
  87. hr = pStm->Read( &isremote, sizeof( BOOL ), &count );
  88. if( !SUCCEEDED( hr ) ) {
  89. break;
  90. }
  91. if( isremote == TRUE ) {
  92. // remote
  93. hr = pStm->Read( &machineName, MAX_COMPUTERNAME_LENGTH * 2, &count );
  94. if( !SUCCEEDED( hr ) ) {
  95. break;
  96. }
  97. m_pFaxSnapin->globalRoot->SetMachine( (LPTSTR)&machineName );
  98. } else {
  99. // local
  100. m_pFaxSnapin->globalRoot->SetMachine( NULL );
  101. }
  102. } while( 0 );
  103. if( hr != S_OK ) {
  104. m_pFaxSnapin->m_pConsole->MessageBox(::GlobalStringTable->GetString( IDS_LOADSTATE_ERR ),
  105. ::GlobalStringTable->GetString( IDS_ERR_TITLE ),
  106. MB_OK,
  107. &iResult);
  108. }
  109. m_bDirtyFlag = FALSE;
  110. return hr;
  111. }
  112. HRESULT
  113. STDMETHODCALLTYPE
  114. CFaxPersistStream::Save(
  115. /* [unique] */ IN IStream __RPC_FAR *pStm,
  116. IN BOOL fClearDirty)
  117. /*++
  118. Routine Description:
  119. This routine save the snapin state to the stream.
  120. Arguments:
  121. pStm - the target stream
  122. fClearDirty - TRUE to clear the dirty flag.
  123. Return Value:
  124. HRESULT indicating SUCCEEDED() or FAILED()
  125. --*/
  126. {
  127. DebugPrint(( TEXT("Trace: CFaxPersistStream::Save") ));
  128. assert( pStm != NULL );
  129. assert( m_pFaxSnapin != NULL );
  130. ULONG count;
  131. int iResult;
  132. HRESULT hr;
  133. BOOL r;
  134. do {
  135. if( m_pFaxSnapin->globalRoot->GetMachine() != NULL ) {
  136. // remote
  137. r = TRUE;
  138. hr = pStm->Write( &r, sizeof(BOOL), &count );
  139. if( !SUCCEEDED( hr ) ) {
  140. break;
  141. }
  142. hr = pStm->Write( const_cast<PVOID>(m_pFaxSnapin->globalRoot->GetMachine()),
  143. MAX_COMPUTERNAME_LENGTH * 2, &count );
  144. if( !SUCCEEDED( hr ) ) {
  145. break;
  146. }
  147. } else {
  148. // local
  149. r = FALSE;
  150. hr = pStm->Write( &r, sizeof(BOOL), &count );
  151. if( !SUCCEEDED( hr ) ) {
  152. break;
  153. }
  154. }
  155. if( fClearDirty == TRUE ) {
  156. m_bDirtyFlag = FALSE;
  157. }
  158. } while( 0 );
  159. if( !SUCCEEDED( hr ) ) {
  160. m_pFaxSnapin->m_pConsole->MessageBox(::GlobalStringTable->GetString( IDS_SAVESTATE_ERR ),
  161. ::GlobalStringTable->GetString( IDS_ERR_TITLE ),
  162. MB_OK,
  163. &iResult);
  164. }
  165. return hr;
  166. }
  167. HRESULT
  168. STDMETHODCALLTYPE
  169. CFaxPersistStream::GetSizeMax(
  170. OUT ULARGE_INTEGER __RPC_FAR *pcbSize)
  171. /*++
  172. Routine Description:
  173. This routine returns the maximum size that the snapin will require
  174. to persist its state.
  175. Arguments:
  176. pcbSize - size of the stream.
  177. Return Value:
  178. HRESULT indicating SUCCEEDED() or FAILED()
  179. --*/
  180. {
  181. DebugPrint(( TEXT("Trace: CFaxPersistStream::GetSizeMax") ));
  182. assert( pcbSize != NULL );
  183. if (!pcbSize) {
  184. return E_FAIL;
  185. }
  186. // return a conservative estimate of the space required in bytes
  187. LISet32( *pcbSize, sizeof( BOOL ) + (MAX_COMPUTERNAME_LENGTH+1) * (sizeof(TCHAR)) );
  188. return S_OK;
  189. }