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.

316 lines
8.5 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1999 **/
  4. /**********************************************************************/
  5. /*
  6. dynext.cpp
  7. dynamic extension helper
  8. FILE HISTORY:
  9. */
  10. #include "stdafx.h"
  11. #include "Dynext.h"
  12. #include "tregkey.h"
  13. #ifdef _DEBUG
  14. #define new DEBUG_NEW
  15. #undef THIS_FILE
  16. static char THIS_FILE[] = __FILE__;
  17. #endif
  18. const TCHAR g_szContextMenu[] = TEXT("ContextMenu");
  19. const TCHAR g_szNameSpace[] = TEXT("NameSpace");
  20. const TCHAR g_szPropertySheet[] = TEXT("PropertySheet");
  21. const TCHAR g_szToolbar[] = TEXT("Toolbar");
  22. const TCHAR g_szExtensions[] = TEXT("Extensions");
  23. const TCHAR g_szTask[] = TEXT("Task");
  24. const TCHAR g_szDynamicExtensions[] = TEXT("Dynamic Extensions");
  25. const TCHAR NODE_TYPES_KEY[] = TEXT("Software\\Microsoft\\MMC\\NodeTypes");
  26. const TCHAR SNAPINS_KEY[] = TEXT("Software\\Microsoft\\MMC\\SnapIns");
  27. CDynamicExtensions::CDynamicExtensions()
  28. {
  29. m_bLoaded = FALSE;
  30. }
  31. CDynamicExtensions::~CDynamicExtensions()
  32. {
  33. }
  34. HRESULT
  35. CDynamicExtensions::SetNode(const GUID * guid)
  36. {
  37. m_guidNode = *guid;
  38. return hrOK;
  39. }
  40. HRESULT
  41. CDynamicExtensions::Reset()
  42. {
  43. HRESULT hr = hrOK;
  44. m_aNameSpace.RemoveAll();
  45. m_aMenu.RemoveAll();
  46. m_aToolbar.RemoveAll();
  47. m_aPropSheet.RemoveAll();
  48. m_aTask.RemoveAll();
  49. m_bLoaded = FALSE;
  50. return hr;
  51. }
  52. HRESULT
  53. CDynamicExtensions::Load()
  54. {
  55. HRESULT hr = hrOK;
  56. LONG lRes;
  57. CGUIDArray aDynExtensions;
  58. Reset();
  59. OLECHAR szGuid[128] = {0};
  60. ::StringFromGUID2(m_guidNode, szGuid, 128);
  61. RegKey regkeyNodeTypes;
  62. // Change by kmurthy: Instead of default, now open for Read
  63. lRes = regkeyNodeTypes.Open(HKEY_LOCAL_MACHINE, NODE_TYPES_KEY, KEY_READ);
  64. Assert(lRes == ERROR_SUCCESS);
  65. if (lRes != ERROR_SUCCESS)
  66. {
  67. return HRESULT_FROM_WIN32(lRes); // failed to open
  68. }
  69. RegKey regkeyNode;
  70. // Change by kmurthy: Instead of default, now open for Read
  71. lRes = regkeyNode.Open(regkeyNodeTypes, szGuid, KEY_READ);
  72. if (lRes != ERROR_SUCCESS)
  73. {
  74. return HRESULT_FROM_WIN32(lRes); // failed to open
  75. }
  76. // open the key for dynamic extensions and enumerate
  77. RegKey regkeyDynExt;
  78. // Change by kmurthy: Instead of default, now open for Read
  79. lRes = regkeyDynExt.Open(regkeyNode, g_szDynamicExtensions, KEY_READ);
  80. if (lRes != ERROR_SUCCESS)
  81. {
  82. return HRESULT_FROM_WIN32(lRes); // failed to open
  83. }
  84. RegKey regkeyExtensions;
  85. // Change by kmurthy: Instead of default, now open for Read
  86. lRes = regkeyExtensions.Open(regkeyNode, g_szExtensions, KEY_READ);
  87. if (lRes != ERROR_SUCCESS)
  88. {
  89. return HRESULT_FROM_WIN32(lRes); // failed to open
  90. }
  91. CString strKey;
  92. RegValueIterator iterDynExt;
  93. iterDynExt.Init(&regkeyDynExt);
  94. while (iterDynExt.Next(&strKey, NULL) == hrOK)
  95. {
  96. GUID guid;
  97. ::CLSIDFromString(((LPTSTR) (LPCTSTR) strKey), &guid);
  98. if (!aDynExtensions.IsInList(guid))
  99. aDynExtensions.Add(guid);
  100. }
  101. // ok, have the list of dynamic extensions, now enumerate the various extension types
  102. // namespace extensions
  103. RegKey regkeyNSExt;
  104. // Change by kmurthy: Instead of default, now open for Read
  105. lRes = regkeyNSExt.Open(regkeyExtensions, g_szNameSpace, KEY_READ);
  106. if (lRes == ERROR_SUCCESS)
  107. {
  108. // enumerate the ns dynamic extensions
  109. RegValueIterator iterNSExt;
  110. iterNSExt.Init(&regkeyNSExt);
  111. while (iterNSExt.Next(&strKey, NULL) == hrOK)
  112. {
  113. GUID guid;
  114. ::CLSIDFromString(((LPTSTR) (LPCTSTR) strKey), &guid);
  115. if (aDynExtensions.IsInList(guid))
  116. m_aNameSpace.Add(guid);
  117. }
  118. }
  119. // Menu extensions
  120. RegKey regkeyMenuExt;
  121. // Change by kmurthy: Instead of default, now open for Read
  122. lRes = regkeyMenuExt.Open(regkeyExtensions, g_szContextMenu, KEY_READ);
  123. if (lRes == ERROR_SUCCESS)
  124. {
  125. // enumerate the ns dynamic extensions
  126. RegValueIterator iterMenuExt;
  127. iterMenuExt.Init(&regkeyMenuExt);
  128. while (iterMenuExt.Next(&strKey, NULL) == hrOK)
  129. {
  130. GUID guid;
  131. ::CLSIDFromString(((LPTSTR) (LPCTSTR) strKey), &guid);
  132. if (aDynExtensions.IsInList(guid))
  133. m_aMenu.Add(guid);
  134. }
  135. }
  136. // toolbar extensions
  137. RegKey regkeyToolbarExt;
  138. // Change by kmurthy: Instead of default, now open for Read
  139. lRes = regkeyToolbarExt.Open(regkeyExtensions, g_szToolbar, KEY_READ);
  140. if (lRes == ERROR_SUCCESS)
  141. {
  142. // enumerate the ns dynamic extensions
  143. RegValueIterator iterToolbarExt;
  144. iterToolbarExt.Init(&regkeyToolbarExt);
  145. while (iterToolbarExt.Next(&strKey, NULL) == hrOK)
  146. {
  147. GUID guid;
  148. ::CLSIDFromString(((LPTSTR) (LPCTSTR) strKey), &guid);
  149. if (aDynExtensions.IsInList(guid))
  150. m_aToolbar.Add(guid);
  151. }
  152. }
  153. // PropPage extensions
  154. RegKey regkeyPSExt;
  155. // Change by kmurthy: Instead of default, now open for Read
  156. lRes = regkeyPSExt.Open(regkeyExtensions, g_szPropertySheet, KEY_READ);
  157. if (lRes == ERROR_SUCCESS)
  158. {
  159. // enumerate the ns dynamic extensions
  160. RegValueIterator iterPSExt;
  161. iterPSExt.Init(&regkeyPSExt);
  162. while (iterPSExt.Next(&strKey, NULL) == hrOK)
  163. {
  164. GUID guid;
  165. ::CLSIDFromString(((LPTSTR) (LPCTSTR) strKey), &guid);
  166. if (aDynExtensions.IsInList(guid))
  167. m_aPropSheet.Add(guid);
  168. }
  169. }
  170. // taskpad extensions
  171. RegKey regkeyTaskExt;
  172. // Change by kmurthy: Instead of default, now open for Read
  173. lRes = regkeyTaskExt.Open(regkeyExtensions, g_szTask, KEY_READ);
  174. if (lRes == ERROR_SUCCESS)
  175. {
  176. // enumerate the ns dynamic extensions
  177. RegValueIterator iterTaskExt;
  178. iterTaskExt.Init(&regkeyTaskExt);
  179. while (iterTaskExt.Next(&strKey, NULL) == hrOK)
  180. {
  181. GUID guid;
  182. ::CLSIDFromString(((LPTSTR) (LPCTSTR) strKey), &guid);
  183. if (aDynExtensions.IsInList(guid))
  184. m_aTask.Add(guid);
  185. }
  186. }
  187. m_bLoaded = TRUE;
  188. return hr;
  189. }
  190. HRESULT
  191. CDynamicExtensions::GetNamespaceExtensions(CGUIDArray & aGuids)
  192. {
  193. HRESULT hr = hrOK;
  194. aGuids.Copy(m_aNameSpace);
  195. return hr;
  196. }
  197. HRESULT
  198. CDynamicExtensions::BuildMMCObjectTypes(HGLOBAL * phGlobal)
  199. {
  200. HRESULT hr = hrOK;
  201. HGLOBAL hGlobal = NULL;
  202. SMMCDynamicExtensions * pDynExt = NULL;
  203. if (phGlobal)
  204. *phGlobal = NULL;
  205. COM_PROTECT_TRY
  206. {
  207. int i;
  208. CGUIDArray aOtherDynExt;
  209. // build our main list of other extension types
  210. // other means everything except namespace
  211. for (i = 0; i < m_aMenu.GetSize(); i++)
  212. {
  213. if (!aOtherDynExt.IsInList(m_aMenu[i]))
  214. aOtherDynExt.Add(m_aMenu[i]);
  215. }
  216. for (i = 0; i < m_aToolbar.GetSize(); i++)
  217. {
  218. if (!aOtherDynExt.IsInList(m_aToolbar[i]))
  219. aOtherDynExt.Add(m_aToolbar[i]);
  220. }
  221. for (i = 0; i < m_aPropSheet.GetSize(); i++)
  222. {
  223. if (!aOtherDynExt.IsInList(m_aPropSheet[i]))
  224. aOtherDynExt.Add(m_aPropSheet[i]);
  225. }
  226. for (i = 0; i < m_aTask.GetSize(); i++)
  227. {
  228. if (!aOtherDynExt.IsInList(m_aTask[i]))
  229. aOtherDynExt.Add(m_aTask[i]);
  230. }
  231. int nCount = (int)aOtherDynExt.GetSize();
  232. hGlobal = (SMMCDynamicExtensions *) ::GlobalAlloc(GMEM_SHARE | GMEM_MOVEABLE,
  233. sizeof(SMMCDynamicExtensions) + (nCount * sizeof(GUID)));
  234. pDynExt = reinterpret_cast<SMMCDynamicExtensions*>(::GlobalLock(hGlobal));
  235. if (!pDynExt)
  236. {
  237. hr = E_OUTOFMEMORY;
  238. goto Error;
  239. }
  240. ZeroMemory(pDynExt, sizeof(SMMCDynamicExtensions) + (nCount * sizeof(GUID)));
  241. // now build the real struct
  242. pDynExt->count = nCount;
  243. for (i = 0; i < nCount; i++)
  244. {
  245. pDynExt->guid[i] = aOtherDynExt[i];
  246. }
  247. ::GlobalUnlock(hGlobal);
  248. COM_PROTECT_ERROR_LABEL;
  249. }
  250. COM_PROTECT_CATCH
  251. if (SUCCEEDED(hr) && phGlobal)
  252. *phGlobal = hGlobal;
  253. return hr;
  254. }