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.

226 lines
5.2 KiB

  1. // This is a part of the Active Template Library.
  2. // Copyright (C) 1996-2001 Microsoft Corporation
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Active Template Library Reference and related
  7. // electronic documentation provided with the library.
  8. // See these sources for detailed information regarding the
  9. // Active Template Library product.
  10. #ifndef __ATLBASE_INL__
  11. #define __ATLBASE_INL__
  12. #pragma once
  13. #ifndef __ATLBASE_H__
  14. #error atlbase.inl requires atlbase.h to be included first
  15. #endif
  16. namespace ATL
  17. {
  18. extern CAtlComModule _AtlComModule;
  19. template <class T>
  20. inline HRESULT CAtlModuleT<T>::RegisterServer(BOOL bRegTypeLib, const CLSID* pCLSID)
  21. {
  22. pCLSID;
  23. bRegTypeLib;
  24. HRESULT hr = S_OK;
  25. #ifndef _ATL_NO_COM_SUPPORT
  26. hr = _AtlComModule.RegisterServer(bRegTypeLib, pCLSID);
  27. #endif // _ATL_NO_COM_SUPPORT
  28. #ifndef _ATL_NO_PERF_SUPPORT
  29. if (SUCCEEDED(hr) && _pPerfRegFunc != NULL)
  30. hr = (*_pPerfRegFunc)(_AtlBaseModule.m_hInst);
  31. #endif
  32. return hr;
  33. }
  34. template <class T>
  35. inline HRESULT CAtlModuleT<T>::UnregisterServer(BOOL bUnRegTypeLib, const CLSID* pCLSID)
  36. {
  37. bUnRegTypeLib;
  38. pCLSID;
  39. HRESULT hr = S_OK;
  40. #ifndef _ATL_NO_PERF_SUPPORT
  41. if (_pPerfUnRegFunc != NULL)
  42. hr = (*_pPerfUnRegFunc)();
  43. #endif
  44. #ifndef _ATL_NO_COM_SUPPORT
  45. if (SUCCEEDED(hr))
  46. hr = _AtlComModule.UnregisterServer(bUnRegTypeLib, pCLSID);
  47. #endif // _ATL_NO_COM_SUPPORT
  48. return hr;
  49. }
  50. inline HRESULT CComModule::Init(_ATL_OBJMAP_ENTRY* p, HINSTANCE /*h*/, const GUID* plibid)
  51. {
  52. if (plibid != NULL)
  53. m_libid = *plibid;
  54. _ATL_OBJMAP_ENTRY* pEntry;
  55. if (p != (_ATL_OBJMAP_ENTRY*)-1)
  56. {
  57. m_pObjMap = p;
  58. if (m_pObjMap != NULL)
  59. {
  60. pEntry = m_pObjMap;
  61. while (pEntry->pclsid != NULL)
  62. {
  63. pEntry->pfnObjectMain(true); //initialize class resources
  64. pEntry++;
  65. }
  66. }
  67. }
  68. for (_ATL_OBJMAP_ENTRY** ppEntry = _AtlComModule.m_ppAutoObjMapFirst; ppEntry < _AtlComModule.m_ppAutoObjMapLast; ppEntry++)
  69. {
  70. if (*ppEntry != NULL)
  71. (*ppEntry)->pfnObjectMain(true); //initialize class resources
  72. }
  73. return S_OK;
  74. }
  75. inline void CComModule::Term()
  76. {
  77. _ATL_OBJMAP_ENTRY* pEntry;
  78. if (m_pObjMap != NULL)
  79. {
  80. pEntry = m_pObjMap;
  81. while (pEntry->pclsid != NULL)
  82. {
  83. if (pEntry->pCF != NULL)
  84. pEntry->pCF->Release();
  85. pEntry->pCF = NULL;
  86. pEntry->pfnObjectMain(false); //cleanup class resources
  87. pEntry++;
  88. }
  89. }
  90. for (_ATL_OBJMAP_ENTRY** ppEntry = _AtlComModule.m_ppAutoObjMapFirst; ppEntry < _AtlComModule.m_ppAutoObjMapLast; ppEntry++)
  91. {
  92. if (*ppEntry != NULL)
  93. (*ppEntry)->pfnObjectMain(false); //cleanup class resources
  94. }
  95. CAtlModuleT<CComModule>::Term();
  96. }
  97. inline HRESULT CComModule::GetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  98. {
  99. if (ppv == NULL)
  100. return E_POINTER;
  101. HRESULT hr = S_OK;
  102. _ATL_OBJMAP_ENTRY* pEntry;
  103. if (m_pObjMap != NULL)
  104. {
  105. pEntry = m_pObjMap;
  106. while (pEntry->pclsid != NULL)
  107. {
  108. if ((pEntry->pfnGetClassObject != NULL) && InlineIsEqualGUID(rclsid, *pEntry->pclsid))
  109. {
  110. if (pEntry->pCF == NULL)
  111. {
  112. CComCritSecLock<CComCriticalSection> lock(_AtlComModule.m_csObjMap, false);
  113. hr = lock.Lock();
  114. if (FAILED(hr))
  115. {
  116. ATLASSERT(0);
  117. break;
  118. }
  119. if (pEntry->pCF == NULL)
  120. hr = pEntry->pfnGetClassObject(pEntry->pfnCreateInstance, __uuidof(IUnknown), (LPVOID*)&pEntry->pCF);
  121. }
  122. if (pEntry->pCF != NULL)
  123. hr = pEntry->pCF->QueryInterface(riid, ppv);
  124. break;
  125. }
  126. pEntry++;
  127. }
  128. }
  129. if (*ppv == NULL && hr == S_OK)
  130. hr = AtlComModuleGetClassObject(&_AtlComModule, rclsid, riid, ppv);
  131. return hr;
  132. }
  133. // Registry support (helpers)
  134. inline HRESULT CComModule::RegisterServer(BOOL bRegTypeLib /*= FALSE*/, const CLSID* pCLSID /*= NULL*/)
  135. {
  136. HRESULT hr = S_OK;
  137. _ATL_OBJMAP_ENTRY* pEntry = m_pObjMap;
  138. if (pEntry != NULL)
  139. {
  140. for (;pEntry->pclsid != NULL; pEntry++)
  141. {
  142. if (pCLSID != NULL)
  143. {
  144. if (!IsEqualGUID(*pCLSID, *pEntry->pclsid))
  145. continue;
  146. }
  147. hr = pEntry->pfnUpdateRegistry(TRUE);
  148. if (FAILED(hr))
  149. break;
  150. hr = AtlRegisterClassCategoriesHelper( *pEntry->pclsid,
  151. pEntry->pfnGetCategoryMap(), TRUE );
  152. if (FAILED(hr))
  153. break;
  154. }
  155. }
  156. if (SUCCEEDED(hr))
  157. hr = CAtlModuleT<CComModule>::RegisterServer(bRegTypeLib, pCLSID);
  158. return hr;
  159. }
  160. inline HRESULT CComModule::UnregisterServer(BOOL bUnRegTypeLib, const CLSID* pCLSID /*= NULL*/)
  161. {
  162. HRESULT hr = S_OK;
  163. _ATL_OBJMAP_ENTRY* pEntry = m_pObjMap;
  164. if (pEntry != NULL)
  165. {
  166. for (;pEntry->pclsid != NULL; pEntry++)
  167. {
  168. if (pCLSID != NULL)
  169. {
  170. if (!IsEqualGUID(*pCLSID, *pEntry->pclsid))
  171. continue;
  172. }
  173. hr = AtlRegisterClassCategoriesHelper( *pEntry->pclsid,
  174. pEntry->pfnGetCategoryMap(), FALSE );
  175. if (FAILED(hr))
  176. break;
  177. hr = pEntry->pfnUpdateRegistry(FALSE); //unregister
  178. if (FAILED(hr))
  179. break;
  180. }
  181. }
  182. if (SUCCEEDED(hr))
  183. hr = CAtlModuleT<CComModule>::UnregisterServer(bUnRegTypeLib, pCLSID);
  184. return hr;
  185. }
  186. inline HRESULT CComModule::UnregisterServer(const CLSID* pCLSID /*= NULL*/)
  187. {
  188. return UnregisterServer(FALSE, pCLSID);
  189. }
  190. } // namespace ATL
  191. #endif // __ATLBASE_INL__