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.

150 lines
7.5 KiB

  1. /*--------------------------------------------------------------------------*
  2. *
  3. * Microsoft Windows
  4. * Copyright (C) Microsoft Corporation, 1992 - 000
  5. *
  6. * File: extension.cpp
  7. *
  8. * Contents:
  9. *
  10. * History: 13-Mar-2000 jeffro Created
  11. *
  12. *--------------------------------------------------------------------------*/
  13. #include "stdafx.hxx"
  14. #include "Extension.h"
  15. static const WCHAR szRegistrationScript[] =
  16. L"HKCR" L"\n"
  17. L"{" L"\n"
  18. L" %VProgID% = s '%VClassName%'" L"\n"
  19. L" {" L"\n"
  20. L" CLSID = s '%VCLSID%'" L"\n"
  21. L" }" L"\n"
  22. L" %VVersionIndependentProgID% = s '%VClassName%'" L"\n"
  23. L" {" L"\n"
  24. L" CurVer = s '%VProgID%'" L"\n"
  25. L" }" L"\n"
  26. L" NoRemove CLSID" L"\n"
  27. L" {" L"\n"
  28. L" ForceRemove %VCLSID% = s '%VClassName%'" L"\n"
  29. L" {" L"\n"
  30. L" ProgID = s '%VProgID%'" L"\n"
  31. L" VersionIndependentProgID = s '%VVersionIndependentProgID%'" L"\n"
  32. L" InprocServer32 = s '%VModule%'" L"\n"
  33. L" {" L"\n"
  34. L" val ThreadingModel = s 'Apartment'" L"\n"
  35. L" }" L"\n"
  36. L" }" L"\n"
  37. L" }" L"\n"
  38. L"}" L"\n"
  39. L"HKLM" L"\n"
  40. L"{" L"\n"
  41. L" NoRemove Software" L"\n"
  42. L" {" L"\n"
  43. L" NoRemove Microsoft" L"\n"
  44. L" {" L"\n"
  45. L" NoRemove MMC" L"\n"
  46. L" {" L"\n"
  47. L" NoRemove SnapIns" L"\n"
  48. L" {" L"\n"
  49. L" ForceRemove %VCLSID%" L"\n"
  50. L" {" L"\n"
  51. L" val NameString = s '%VSnapinName%'" L"\n"
  52. L" }" L"\n"
  53. L" }" L"\n"
  54. L" NoRemove NodeTypes" L"\n"
  55. L" {" L"\n"
  56. L" NoRemove %VExtendedNodeType%" L"\n"
  57. L" {" L"\n"
  58. L" NoRemove Extensions" L"\n"
  59. L" {" L"\n"
  60. L" NoRemove %VExtensionType%" L"\n"
  61. L" {" L"\n"
  62. L" val %VCLSID% = s '%VClassName%'" L"\n"
  63. L" }" L"\n"
  64. L" }" L"\n"
  65. L" }" L"\n"
  66. L" }" L"\n"
  67. L" }" L"\n"
  68. L" }" L"\n"
  69. L" }" L"\n"
  70. L"}";
  71. /*+-------------------------------------------------------------------------*
  72. * CExtension::UpdateRegistry
  73. *
  74. *
  75. *--------------------------------------------------------------------------*/
  76. HRESULT WINAPI CExtension::UpdateRegistry (
  77. BOOL bRegister,
  78. ExtensionType eExtType,
  79. const CLSID& clsidSnapIn,
  80. LPCWSTR pszClassName,
  81. LPCWSTR pszProgID,
  82. LPCWSTR pszVersionIndependentProgID,
  83. LPCWSTR pszExtendedNodeType)
  84. {
  85. DECLARE_SC (sc, _T("CExtension::UpdateRegistry"));
  86. if ((eExtType < eExtType_First) || (eExtType > eExtType_Last))
  87. return ((sc = E_INVALIDARG).ToHr());
  88. /*
  89. * string-ify the CLSID
  90. */
  91. CCoTaskMemPtr<WCHAR> spszClsid;
  92. sc = StringFromCLSID (clsidSnapIn, &spszClsid);
  93. if (sc)
  94. return sc.ToHr();
  95. static const LPCWSTR rgExtTypes[eExtType_Count] =
  96. {
  97. L"Namespace", // eExtType_Namespace
  98. L"ContextMenu", // eExtType_ContextMenu
  99. L"PropertySheet", // eExtType_PropertySheet
  100. L"Taskpad", // eExtType_Taskpad
  101. L"View", // eExtType_View
  102. };
  103. /*
  104. * get the filename for the module
  105. */
  106. USES_CONVERSION;
  107. TCHAR szModule[_MAX_PATH];
  108. GetModuleFileName (_Module.GetModuleInstance(), szModule, countof(szModule));
  109. /*
  110. * specify the standard object substitution parameters for CRegObject
  111. */
  112. ::ATL::ATL::CRegObject ro; // hack around nested namespace bug in ATL30
  113. _ATL_REGMAP_ENTRY rgObjEntries[] =
  114. {
  115. { L"VModule", T2W(szModule) },
  116. { L"VCLSID", spszClsid },
  117. { L"VExtendedNodeType", pszExtendedNodeType },
  118. { L"VClassName", pszClassName },
  119. { L"VProgID", pszProgID },
  120. { L"VVersionIndependentProgID", pszVersionIndependentProgID },
  121. { L"VExtensionType", rgExtTypes[eExtType] },
  122. { L"VSnapinName", pszClassName}
  123. };
  124. for (int i = 0; i < countof (rgObjEntries); i++)
  125. {
  126. sc = ro.AddReplacement (rgObjEntries[i].szKey, rgObjEntries[i].szData);
  127. if (sc)
  128. return (sc.ToHr());
  129. }
  130. /*
  131. * (un)register!
  132. */
  133. sc = (bRegister) ? ro.StringRegister (szRegistrationScript)
  134. : ro.StringUnregister (szRegistrationScript);
  135. return sc.ToHr();
  136. }