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.

278 lines
4.9 KiB

  1. /*
  2. * classes.cxx
  3. */
  4. #include "server.hxx"
  5. #include "classes.hxx"
  6. //
  7. // MyObject implementation.
  8. //
  9. MyObject::MyObject( int ActType ) :
  10. Refs(0),
  11. ActivationType(ActType),
  12. PersistFileObj(this),
  13. PersistStorageObj(this),
  14. GooberObj(this)
  15. {
  16. }
  17. MyObject::~MyObject()
  18. {
  19. }
  20. //
  21. // MyObject IUnknown.
  22. //
  23. HRESULT STDMETHODCALLTYPE
  24. MyObject::QueryInterface (
  25. REFIID iid,
  26. void ** ppv )
  27. {
  28. HRESULT hr = E_NOINTERFACE;
  29. *ppv = 0;
  30. if ( memcmp(&iid, &IID_IUnknown, sizeof(IID)) == 0 )
  31. *ppv = this;
  32. else if ( (memcmp(&iid, &IID_IPersist, sizeof(IID)) == 0) ||
  33. (memcmp(&iid, &IID_IPersistFile, sizeof(IID)) == 0) )
  34. *ppv = &PersistFileObj;
  35. else if ( memcmp(&iid, &IID_IPersistStorage, sizeof(IID)) == 0 )
  36. *ppv = &PersistStorageObj;
  37. else if ( memcmp(&iid, &IID_IGoober, sizeof(IID)) == 0 )
  38. *ppv = &GooberObj;
  39. else
  40. return E_NOINTERFACE;
  41. ((IUnknown *)(*ppv))->AddRef();
  42. return S_OK;
  43. }
  44. ULONG STDMETHODCALLTYPE
  45. MyObject::AddRef()
  46. {
  47. Refs++;
  48. return Refs;
  49. }
  50. ULONG STDMETHODCALLTYPE
  51. MyObject::Release()
  52. {
  53. unsigned long Count;
  54. Count = --Refs;
  55. if ( Count == 0 )
  56. {
  57. delete this;
  58. // Decrement the object count.
  59. if ( --ObjectCount == 0 )
  60. ShutDown();
  61. }
  62. return Count;
  63. }
  64. //
  65. // PersistFile implementation.
  66. //
  67. PersistFile::PersistFile( MyObject * pObj ) :
  68. pObject(pObj)
  69. {
  70. }
  71. //
  72. // PersistFile IUnknown.
  73. //
  74. IUnknownMETHODS( PersistFile )
  75. //
  76. // PersistFile IPersist.
  77. //
  78. HRESULT STDMETHODCALLTYPE
  79. PersistFile::GetClassID(
  80. CLSID * pClassID )
  81. {
  82. if ( pObject->GetActivationType() == LOCAL )
  83. memcpy( pClassID, &CLSID_ActLocal, sizeof(IID) );
  84. else if ( pObject->GetActivationType() == REMOTE )
  85. memcpy( pClassID, &CLSID_ActRemote, sizeof(IID) );
  86. else if (pObject->GetActivationType() == ATBITS )
  87. memcpy( pClassID, &CLSID_ActAtStorage, sizeof(IID) );
  88. else if (pObject->GetActivationType() == INPROC )
  89. memcpy( pClassID, &CLSID_ActInproc, sizeof(IID) );
  90. return S_OK;
  91. }
  92. //
  93. // PersistFile IPersistFile
  94. //
  95. HRESULT STDMETHODCALLTYPE
  96. PersistFile::IsDirty()
  97. {
  98. return S_FALSE;
  99. }
  100. HRESULT STDMETHODCALLTYPE
  101. PersistFile::Load(
  102. LPCOLESTR pszFileName,
  103. DWORD dwMode )
  104. {
  105. /** Doesn't work until we have security stuff...
  106. HANDLE hFile;
  107. //
  108. // Verify that we can open the file.
  109. //
  110. hFile = CreateFile(
  111. pszFileName,
  112. dwMode,
  113. 0,
  114. NULL,
  115. OPEN_EXISTING,
  116. FILE_ATTRIBUTE_NORMAL,
  117. NULL );
  118. if ( hFile == INVALID_HANDLE_VALUE )
  119. return HRESULT_FROM_WIN32( GetLastError() );
  120. CloseHandle( hFile );
  121. **/
  122. return S_OK;
  123. }
  124. HRESULT STDMETHODCALLTYPE
  125. PersistFile::Save(
  126. LPCOLESTR pszFileName,
  127. BOOL fRemember )
  128. {
  129. return S_OK;
  130. }
  131. HRESULT STDMETHODCALLTYPE
  132. PersistFile::SaveCompleted(
  133. LPCOLESTR pszFileName )
  134. {
  135. return S_OK;
  136. }
  137. HRESULT STDMETHODCALLTYPE
  138. PersistFile::GetCurFile(
  139. LPOLESTR * ppszFileName )
  140. {
  141. *ppszFileName = 0;
  142. return S_OK;
  143. }
  144. //
  145. // PersistStorage implementation.
  146. //
  147. PersistStorage::PersistStorage( MyObject * pObj ) :
  148. pObject(pObj)
  149. {
  150. }
  151. //
  152. // PersistStorage IUnknown.
  153. //
  154. IUnknownMETHODS( PersistStorage )
  155. //
  156. // PersistStorage IPersist.
  157. //
  158. HRESULT STDMETHODCALLTYPE
  159. PersistStorage::GetClassID(
  160. CLSID * pClassID )
  161. {
  162. if ( pObject->GetActivationType() == LOCAL )
  163. memcpy( pClassID, &CLSID_ActLocal, sizeof(IID) );
  164. else if ( pObject->GetActivationType() == REMOTE )
  165. memcpy( pClassID, &CLSID_ActRemote, sizeof(IID) );
  166. else if (pObject->GetActivationType() == ATBITS )
  167. memcpy( pClassID, &CLSID_ActAtStorage, sizeof(IID) );
  168. else if (pObject->GetActivationType() == INPROC )
  169. memcpy( pClassID, &CLSID_ActInproc, sizeof(IID) );
  170. return S_OK;
  171. }
  172. //
  173. // PersistStorage IPersistStorage
  174. //
  175. HRESULT STDMETHODCALLTYPE
  176. PersistStorage::IsDirty()
  177. {
  178. return S_FALSE;
  179. }
  180. HRESULT STDMETHODCALLTYPE
  181. PersistStorage::InitNew(
  182. IStorage * pStg )
  183. {
  184. return S_OK;
  185. }
  186. HRESULT STDMETHODCALLTYPE
  187. PersistStorage::Load(
  188. IStorage * pStg )
  189. {
  190. return S_OK;
  191. }
  192. HRESULT STDMETHODCALLTYPE
  193. PersistStorage::Save(
  194. IStorage * pStgSave,
  195. BOOL fSameAsLoad )
  196. {
  197. return S_OK;
  198. }
  199. HRESULT STDMETHODCALLTYPE
  200. PersistStorage::SaveCompleted(
  201. IStorage * pStgNew )
  202. {
  203. return S_OK;
  204. }
  205. HRESULT STDMETHODCALLTYPE
  206. PersistStorage::HandsOffStorage()
  207. {
  208. return S_OK;
  209. }
  210. //
  211. // Goober implementation
  212. //
  213. Goober::Goober( MyObject * pObj ) :
  214. pObject(pObj)
  215. {
  216. }
  217. //
  218. // Goober IUnknown.
  219. //
  220. IUnknownMETHODS( Goober )
  221. //
  222. // Goober IGoober.
  223. //
  224. HRESULT STDMETHODCALLTYPE
  225. Goober::Ping()
  226. {
  227. return S_OK;
  228. }