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.

219 lines
4.4 KiB

  1. //+------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996 - 1997
  5. //
  6. // File: cclsto.cxx
  7. //
  8. // Contents: Class Factory and IUnknown methods for CAppContainer
  9. //
  10. // Author: DebiM
  11. //
  12. //-------------------------------------------------------------------------
  13. #include "cstore.hxx"
  14. //
  15. // Constructor for Class Container Class factory
  16. //
  17. unsigned long gulcappcon = 0;
  18. CAppContainerCF::CAppContainerCF()
  19. {
  20. m_uRefs = 1;
  21. InterlockedIncrement((long *) &gulcappcon );
  22. }
  23. //
  24. // Destructor
  25. //
  26. CAppContainerCF::~CAppContainerCF()
  27. {
  28. InterlockedDecrement((long *) &gulcappcon );
  29. }
  30. HRESULT __stdcall CAppContainerCF::QueryInterface(REFIID riid, void * * ppvObject)
  31. {
  32. IUnknown *pUnkTemp = NULL;
  33. SCODE sc = S_OK;
  34. if( IsEqualIID( IID_IUnknown, riid ) )
  35. {
  36. pUnkTemp = (IUnknown *)(ITypeLib *)this;
  37. }
  38. else if( IsEqualIID( IID_IClassFactory, riid ) )
  39. {
  40. pUnkTemp = (IUnknown *)(IClassFactory *)this;
  41. }
  42. else if( IsEqualIID( IID_IParseDisplayName, riid ) )
  43. {
  44. pUnkTemp = (IUnknown *)(IParseDisplayName *)this;
  45. }
  46. else
  47. {
  48. sc = (E_NOINTERFACE);
  49. }
  50. if((pUnkTemp != NULL) && (SUCCEEDED(sc)))
  51. {
  52. *ppvObject = (void * )pUnkTemp;
  53. pUnkTemp->AddRef();
  54. }
  55. return(sc);
  56. }
  57. ULONG __stdcall CAppContainerCF::AddRef()
  58. {
  59. InterlockedIncrement(( long * )&m_uRefs );
  60. return m_uRefs;
  61. }
  62. ULONG __stdcall CAppContainerCF::Release()
  63. {
  64. unsigned long uTmp = InterlockedDecrement((long *)&m_uRefs);
  65. unsigned long cRef = m_uRefs;
  66. // 0 is the only valid value to check
  67. if (uTmp == 0)
  68. {
  69. delete this;
  70. }
  71. return(cRef);
  72. }
  73. //
  74. // IClassFactory Overide
  75. //
  76. HRESULT __stdcall CAppContainerCF::CreateInstance(IUnknown * pUnkOuter, REFIID riid, void * * ppvObject)
  77. {
  78. CAppContainer * pIUnk = NULL;
  79. SCODE sc = S_OK;
  80. if( pUnkOuter == NULL )
  81. {
  82. if( (pIUnk = new CAppContainer()) != NULL)
  83. {
  84. sc = pIUnk->QueryInterface( riid , ppvObject );
  85. if(FAILED(sc))
  86. {
  87. sc = E_UNEXPECTED;
  88. }
  89. pIUnk->Release();
  90. }
  91. else
  92. sc = E_OUTOFMEMORY;
  93. }
  94. else
  95. {
  96. return E_INVALIDARG;
  97. }
  98. return (sc);
  99. }
  100. //
  101. // Creates an instance and binds to the container.
  102. // Fails if the bind fails.
  103. // Returns the errorcode as the second parameter
  104. //
  105. HRESULT __stdcall CAppContainerCF::CreateConnectedInstance(
  106. LPOLESTR pszPath, void * * ppvObject)
  107. {
  108. CAppContainer * pIUnk = NULL;
  109. SCODE sc = S_OK;
  110. HRESULT hr;
  111. if ((pIUnk = new CAppContainer(pszPath, &sc)) != NULL)
  112. {
  113. if (SUCCEEDED(sc))
  114. {
  115. sc = pIUnk->QueryInterface( IID_IClassAccess, ppvObject );
  116. if(FAILED(sc))
  117. {
  118. sc = E_UNEXPECTED;
  119. }
  120. }
  121. else
  122. CSDbgPrint(("CS: Connect to Store Failed. hr = 0x%x.\n", sc));
  123. pIUnk->Release();
  124. }
  125. else
  126. sc = E_OUTOFMEMORY;
  127. return (sc);
  128. }
  129. HRESULT __stdcall CAppContainerCF::LockServer(BOOL fLock)
  130. {
  131. if(fLock)
  132. { InterlockedIncrement((long *) &gulcappcon ); }
  133. else
  134. { InterlockedDecrement((long *) &gulcappcon ); }
  135. return(S_OK);
  136. }
  137. //
  138. // IUnknown methods for CAppContainer
  139. //
  140. //
  141. HRESULT __stdcall CAppContainer::QueryInterface(REFIID riid, void * * ppvObject)
  142. {
  143. IUnknown *pUnkTemp = NULL;
  144. SCODE sc = S_OK;
  145. if( IsEqualIID( IID_IUnknown, riid ) )
  146. {
  147. pUnkTemp = (IUnknown *)(IClassAccess *)this;
  148. }
  149. else if( IsEqualIID( IID_IClassAccess, riid ) )
  150. {
  151. pUnkTemp = (IUnknown *)(IClassAccess *)this;
  152. }
  153. /*
  154. else if( IsEqualIID( IID_IClassRefresh, riid ) )
  155. {
  156. pUnkTemp = (IUnknown *)(IClassRefresh *)this;
  157. }
  158. else if( IsEqualIID( IID_ICatInformation, riid ) )
  159. {
  160. pUnkTemp = (IUnknown *)(ICatInformation *)this;
  161. }
  162. */
  163. else
  164. {
  165. sc = (E_NOINTERFACE);
  166. }
  167. if((pUnkTemp != NULL) && (SUCCEEDED(sc)))
  168. {
  169. *ppvObject = (void * )pUnkTemp;
  170. pUnkTemp->AddRef();
  171. }
  172. return(sc);
  173. }
  174. ULONG __stdcall CAppContainer::AddRef()
  175. {
  176. InterlockedIncrement(( long * )&m_uRefs );
  177. return m_uRefs;
  178. }
  179. ULONG __stdcall CAppContainer::Release()
  180. {
  181. unsigned long uTmp = InterlockedDecrement((long *)&m_uRefs);
  182. unsigned long cRef = m_uRefs;
  183. if (uTmp == 0)
  184. {
  185. delete this;
  186. }
  187. return(cRef);
  188. }