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.

224 lines
7.9 KiB

  1. /*--------------------------------------------------------------------------*
  2. *
  3. * Microsoft Windows
  4. * Copyright (C) Microsoft Corporation, 2000 - 2000
  5. *
  6. * File: viewext.cpp
  7. *
  8. * Contents: Implementation file for the built-in view extension snapin that extends
  9. * the snapins that ship with windows.
  10. *
  11. * History: 21 March 2000 vivekj Created
  12. *
  13. *--------------------------------------------------------------------------*/
  14. #include "stdafx.h"
  15. #include "viewext.h"
  16. #include "util.h"
  17. #include "fldrsnap.h" // for ScFormatIndirectSnapInName
  18. // {B708457E-DB61-4c55-A92F-0D4B5E9B1224}
  19. const CLSID CLSID_ViewExtSnapin = { 0xb708457e, 0xdb61, 0x4c55, { 0xa9, 0x2f, 0xd, 0x4b, 0x5e, 0x9b, 0x12, 0x24 } };
  20. const GUID GUID_ExplorerView = { 0x34723cbb, 0x9676, 0x4770, { 0xa8, 0xdf, 0x60, 0x8, 0x8, 0x53, 0x47, 0x7a } };
  21. #ifdef DBG
  22. CTraceTag tagVivekHardCodedViewExtPath(_T("Vivek"), _T("Use view extension d:\\views.htm"));
  23. CTraceTag tagDllRegistration (_T("MMC Dll Registration"), _T("View extension registration"));
  24. #endif
  25. /*+-------------------------------------------------------------------------*
  26. *
  27. * CViewExtensionSnapin::GetViews
  28. *
  29. * PURPOSE: Returns the URL for the extended view.
  30. *
  31. * PARAMETERS:
  32. * LPDATAOBJECT pDataObject :
  33. * LPVIEWEXTENSIONCALLBACK pViewExtensionCallback: The callback to add the views into
  34. *
  35. * RETURNS:
  36. * HRESULT
  37. *
  38. *+-------------------------------------------------------------------------*/
  39. HRESULT
  40. CViewExtensionSnapin::GetViews(LPDATAOBJECT pDataObject, LPVIEWEXTENSIONCALLBACK pViewExtensionCallback)
  41. {
  42. DECLARE_SC(sc, TEXT("CViewExtensionSnapin::GetView"));
  43. // check parameters
  44. sc = ScCheckPointers(pDataObject, pViewExtensionCallback, E_UNEXPECTED);
  45. if(sc)
  46. return sc.ToHr();
  47. MMC_EXT_VIEW_DATA extViewData = {0};
  48. USES_CONVERSION;
  49. TCHAR szBuffer[MAX_PATH * 2];
  50. #ifdef DBG
  51. if (tagVivekHardCodedViewExtPath.FAny()) // use the hard coded path to make changes easier.
  52. {
  53. sc = StringCchCopy(szBuffer, countof(szBuffer), _T("d:\\newnt\\admin\\mmcdev\\nodemgr\\viewext\\views.htm"));
  54. if(sc)
  55. return sc.ToHr();
  56. }
  57. else
  58. {
  59. #endif // DBG
  60. // get the fully qualified path to the dll and append the html page
  61. sc = StringCchCopy(szBuffer, countof(szBuffer), _T("res://"));
  62. if(sc)
  63. return sc.ToHr();
  64. DWORD dwRet = ::GetModuleFileName (_Module.GetModuleInstance(), szBuffer + _tcslen(szBuffer), countof(szBuffer) - _tcslen(szBuffer));
  65. if(0==dwRet)
  66. return (sc.FromLastError().ToHr());
  67. sc = StringCchCat(szBuffer, countof(szBuffer), _T("/views.htm"));
  68. if(sc)
  69. return sc.ToHr();
  70. #ifdef DBG
  71. }
  72. #endif // DBG
  73. extViewData.pszURL = T2OLE(szBuffer);
  74. // set the GUID identifier of the view
  75. extViewData.viewID = GUID_ExplorerView;
  76. // set the title for the string.
  77. CStr strViewTitle;
  78. strViewTitle.LoadString(GetStringModule(), IDS_ExplorerView); // the name of the view
  79. extViewData.pszViewTitle = T2COLE(strViewTitle);
  80. // does not replace the normal view
  81. extViewData.bReplacesDefaultView = FALSE;
  82. sc = pViewExtensionCallback->AddView(&extViewData);
  83. return sc.ToHr();
  84. }
  85. /*+-------------------------------------------------------------------------*
  86. * szViewExtRegScript
  87. *
  88. * Registration script used by RegisterViewExtension.
  89. *--------------------------------------------------------------------------*/
  90. static const WCHAR szViewExtRegScript[] =
  91. L"HKLM" L"\n"
  92. L"{" L"\n"
  93. L" NoRemove Software" L"\n"
  94. L" {" L"\n"
  95. L" NoRemove Microsoft" L"\n"
  96. L" {" L"\n"
  97. L" NoRemove MMC" L"\n"
  98. L" {" L"\n"
  99. L" NoRemove SnapIns" L"\n"
  100. L" {" L"\n"
  101. L" ForceRemove %VCLSID%" L"\n"
  102. L" {" L"\n"
  103. L" val NameString = s '%VSnapinName%'" L"\n"
  104. L" val NameStringIndirect = s '%VSnapinNameIndirect%'" L"\n"
  105. L" }" L"\n"
  106. L" }" L"\n"
  107. L" }" L"\n"
  108. L" }" L"\n"
  109. L" }" L"\n"
  110. L"}";
  111. /*+-------------------------------------------------------------------------*
  112. * RegisterViewExtension
  113. *
  114. * Note1: registers mmcndmgr.dll as the module without any path.
  115. *
  116. * Note2: Snapin registration does not include nodetypes/about/version...
  117. *
  118. *--------------------------------------------------------------------------*/
  119. HRESULT WINAPI RegisterViewExtension (BOOL bRegister, CObjectRegParams& rObjParams, int idSnapinName)
  120. {
  121. DECLARE_SC (sc, _T("RegisterViewExtension"));
  122. // First register the com object for this inproc server.
  123. sc = MMCUpdateRegistry (bRegister, &rObjParams, NULL);
  124. if (sc)
  125. return sc.ToHr();
  126. /*
  127. * string-ify the CLSID
  128. */
  129. CCoTaskMemPtr<WCHAR> spszClsid;
  130. sc = StringFromCLSID (rObjParams.m_clsid, &spszClsid);
  131. if (sc)
  132. return sc.ToHr();
  133. /*
  134. * load the default snap-in name
  135. */
  136. HINSTANCE hInst = GetStringModule();
  137. CStr strSnapinName;
  138. strSnapinName.LoadString (hInst, idSnapinName);
  139. /*
  140. * format a MUI-friendly snap-in name
  141. */
  142. CStr strSnapinNameIndirect;
  143. sc = ScFormatIndirectSnapInName (hInst, idSnapinName, strSnapinNameIndirect);
  144. if (sc)
  145. return (sc.ToHr());
  146. USES_CONVERSION;
  147. #ifdef DBG
  148. extern CTraceTag tagDllRegistration;
  149. std::wstring strReplacements;
  150. #endif
  151. #ifdef _ATL_NAMESPACE_BUG_FIXED
  152. ::ATL::CRegObject ro; // hack around nested namespace bug in ATL30
  153. #else
  154. MMC_ATL::ATL::CRegObject ro; // hack around nested namespace bug in ATL30
  155. #endif
  156. _ATL_REGMAP_ENTRY rgExtensionEntries[] =
  157. {
  158. { L"VCLSID", spszClsid },
  159. { L"VSnapinName", T2CW (strSnapinName) },
  160. { L"VSnapinNameIndirect", T2CW (strSnapinNameIndirect) },
  161. { L"VClassName", rObjParams.m_strClassName.data() },
  162. { L"VProgID", rObjParams.m_strProgID.data() },
  163. { L"VVersionIndependentProgID", rObjParams.m_strVersionIndependentProgID.data() },
  164. };
  165. for (int j = 0; j < countof (rgExtensionEntries); j++)
  166. {
  167. sc = ro.AddReplacement (rgExtensionEntries[j].szKey, rgExtensionEntries[j].szData);
  168. if (sc)
  169. return (sc.ToHr());
  170. AddReplacementTrace (strReplacements,
  171. rgExtensionEntries[j].szKey,
  172. rgExtensionEntries[j].szData);
  173. }
  174. Trace (tagDllRegistration, _T("Registration script:\n%s"), W2CT(szViewExtRegScript));
  175. Trace (tagDllRegistration, W2CT(strReplacements.data()));
  176. /*
  177. * (un)register!
  178. */
  179. sc = (bRegister) ? ro.StringRegister (szViewExtRegScript)
  180. : ro.StringUnregister (szViewExtRegScript);
  181. if (sc)
  182. return sc.ToHr();
  183. return sc.ToHr();
  184. }