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.

209 lines
7.3 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. _tcscpy (szBuffer, _T("d:\\newnt\\admin\\mmcdev\\nodemgr\\viewext\\views.htm"));
  54. }
  55. else
  56. {
  57. #endif // DBG
  58. // get the fully qualified path to the dll and append the html page
  59. _tcscpy (szBuffer, _T("res://"));
  60. ::GetModuleFileName (_Module.GetModuleInstance(), szBuffer + _tcslen(szBuffer), MAX_PATH);
  61. _tcscat (szBuffer, _T("/views.htm"));
  62. #ifdef DBG
  63. }
  64. #endif // DBG
  65. extViewData.pszURL = T2OLE(szBuffer);
  66. // set the GUID identifier of the view
  67. extViewData.viewID = GUID_ExplorerView;
  68. // set the title for the string.
  69. CStr strViewTitle;
  70. strViewTitle.LoadString(GetStringModule(), IDS_ExplorerView); // the name of the view
  71. extViewData.pszViewTitle = T2COLE(strViewTitle);
  72. // does not replace the normal view
  73. extViewData.bReplacesDefaultView = FALSE;
  74. sc = pViewExtensionCallback->AddView(&extViewData);
  75. return sc.ToHr();
  76. }
  77. /*+-------------------------------------------------------------------------*
  78. * szViewExtRegScript
  79. *
  80. * Registration script used by RegisterViewExtension.
  81. *--------------------------------------------------------------------------*/
  82. static const WCHAR szViewExtRegScript[] =
  83. L"HKLM" L"\n"
  84. L"{" L"\n"
  85. L" NoRemove Software" L"\n"
  86. L" {" L"\n"
  87. L" NoRemove Microsoft" L"\n"
  88. L" {" L"\n"
  89. L" NoRemove MMC" L"\n"
  90. L" {" L"\n"
  91. L" NoRemove SnapIns" L"\n"
  92. L" {" L"\n"
  93. L" ForceRemove %VCLSID%" L"\n"
  94. L" {" L"\n"
  95. L" val NameString = s '%VSnapinName%'" L"\n"
  96. L" val NameStringIndirect = s '%VSnapinNameIndirect%'" L"\n"
  97. L" }" L"\n"
  98. L" }" L"\n"
  99. L" }" L"\n"
  100. L" }" L"\n"
  101. L" }" L"\n"
  102. L"}";
  103. /*+-------------------------------------------------------------------------*
  104. * RegisterViewExtension
  105. *
  106. * Note1: registers mmcndmgr.dll as the module without any path.
  107. *
  108. * Note2: Snapin registration does not include nodetypes/about/version...
  109. *
  110. *--------------------------------------------------------------------------*/
  111. HRESULT WINAPI RegisterViewExtension (BOOL bRegister, CObjectRegParams& rObjParams, int idSnapinName)
  112. {
  113. DECLARE_SC (sc, _T("RegisterViewExtension"));
  114. // First register the com object for this inproc server.
  115. sc = MMCUpdateRegistry (bRegister, &rObjParams, NULL);
  116. if (sc)
  117. return sc.ToHr();
  118. /*
  119. * string-ify the CLSID
  120. */
  121. CCoTaskMemPtr<WCHAR> spszClsid;
  122. sc = StringFromCLSID (rObjParams.m_clsid, &spszClsid);
  123. if (sc)
  124. return sc.ToHr();
  125. /*
  126. * load the default snap-in name
  127. */
  128. HINSTANCE hInst = GetStringModule();
  129. CStr strSnapinName;
  130. strSnapinName.LoadString (hInst, idSnapinName);
  131. /*
  132. * format a MUI-friendly snap-in name
  133. */
  134. CStr strSnapinNameIndirect;
  135. sc = ScFormatIndirectSnapInName (hInst, idSnapinName, strSnapinNameIndirect);
  136. if (sc)
  137. return (sc.ToHr());
  138. USES_CONVERSION;
  139. #ifdef DBG
  140. extern CTraceTag tagDllRegistration;
  141. std::wstring strReplacements;
  142. #endif
  143. MMC_ATL::ATL::CRegObject ro; // hack around nested namespace bug in ATL30
  144. _ATL_REGMAP_ENTRY rgExtensionEntries[] =
  145. {
  146. { L"VCLSID", spszClsid },
  147. { L"VSnapinName", T2CW (strSnapinName) },
  148. { L"VSnapinNameIndirect", T2CW (strSnapinNameIndirect) },
  149. { L"VClassName", rObjParams.m_strClassName.data() },
  150. { L"VProgID", rObjParams.m_strProgID.data() },
  151. { L"VVersionIndependentProgID", rObjParams.m_strVersionIndependentProgID.data() },
  152. };
  153. for (int j = 0; j < countof (rgExtensionEntries); j++)
  154. {
  155. sc = ro.AddReplacement (rgExtensionEntries[j].szKey, rgExtensionEntries[j].szData);
  156. if (sc)
  157. return (sc.ToHr());
  158. AddReplacementTrace (strReplacements,
  159. rgExtensionEntries[j].szKey,
  160. rgExtensionEntries[j].szData);
  161. }
  162. Trace (tagDllRegistration, _T("Registration script:\n%s"), W2CT(szViewExtRegScript));
  163. Trace (tagDllRegistration, W2CT(strReplacements.data()));
  164. /*
  165. * (un)register!
  166. */
  167. sc = (bRegister) ? ro.StringRegister (szViewExtRegScript)
  168. : ro.StringUnregister (szViewExtRegScript);
  169. if (sc)
  170. return sc.ToHr();
  171. return sc.ToHr();
  172. }