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.

132 lines
3.0 KiB

  1. //____________________________________________________________________________
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1995 - 1996.
  5. //
  6. // File: SnpInReg.cpp
  7. //
  8. // Contents:
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // History: 11/10/1998 JonN Created
  15. //
  16. //____________________________________________________________________________
  17. #include "stdafx.h"
  18. #pragma hdrstop
  19. #include "..\corecopy\regkey.h"
  20. #include "snapreg.h"
  21. #include "stdutils.h" // g_aNodetypeGUIDs
  22. HRESULT RegisterNodetypes(
  23. AMC::CRegKey& regkeyParent,
  24. int* aiNodetypeIndexes,
  25. int cNodetypeIndexes )
  26. {
  27. try
  28. {
  29. AMC::CRegKey regkeyNodeTypes;
  30. regkeyNodeTypes.CreateKeyEx( regkeyParent, _T("NodeTypes") );
  31. AMC::CRegKey regkeyNodeType;
  32. for (int i = 0; i < cNodetypeIndexes; i++)
  33. {
  34. regkeyNodeType.CreateKeyEx(
  35. regkeyNodeTypes,
  36. g_aNodetypeGuids[aiNodetypeIndexes[i]].bstr );
  37. regkeyNodeType.CloseKey();
  38. }
  39. }
  40. catch (COleException* e)
  41. {
  42. ASSERT(FALSE);
  43. e->Delete();
  44. return SELFREG_E_CLASS;
  45. }
  46. return S_OK;
  47. }
  48. HRESULT RegisterSnapin(
  49. AMC::CRegKey& regkeySnapins,
  50. LPCTSTR pszSnapinGUID,
  51. BSTR bstrPrimaryNodetype,
  52. UINT residSnapinName,
  53. UINT residProvider,
  54. UINT residVersion,
  55. bool fStandalone,
  56. LPCTSTR pszAboutGUID,
  57. int* aiNodetypeIndexes,
  58. int cNodetypeIndexes )
  59. {
  60. HRESULT hr = S_OK;
  61. try
  62. {
  63. AMC::CRegKey regkeySnapin;
  64. CString strSnapinName, strProvider, strVersion;
  65. if ( !strSnapinName.LoadString(residSnapinName)
  66. || !strProvider.LoadString(residProvider)
  67. || !strVersion.LoadString(residVersion)
  68. )
  69. {
  70. ASSERT(FALSE);
  71. return SELFREG_E_CLASS;
  72. }
  73. regkeySnapin.CreateKeyEx( regkeySnapins, pszSnapinGUID );
  74. if (NULL != bstrPrimaryNodetype)
  75. {
  76. regkeySnapin.SetString( _T("NodeType"), bstrPrimaryNodetype );
  77. }
  78. regkeySnapin.SetString( _T("NameString"), strSnapinName );
  79. regkeySnapin.SetString( _T("Provider"), strProvider );
  80. regkeySnapin.SetString( _T("Version"), strVersion );
  81. if (fStandalone)
  82. {
  83. AMC::CRegKey regkeyStandalone;
  84. regkeyStandalone.CreateKeyEx( regkeySnapin, _T("StandAlone") );
  85. }
  86. if (NULL != pszAboutGUID)
  87. {
  88. regkeySnapin.SetString( _T("About"), pszAboutGUID );
  89. }
  90. if ( NULL != aiNodetypeIndexes && 0 != cNodetypeIndexes )
  91. {
  92. hr = RegisterNodetypes(
  93. regkeySnapin,
  94. aiNodetypeIndexes,
  95. cNodetypeIndexes );
  96. }
  97. //
  98. // JonN 4/25/00
  99. // 100624: MUI: MMC: Shared Folders snap-in stores
  100. // its display information in the registry
  101. //
  102. // MMC now supports NameStringIndirect
  103. //
  104. TCHAR achModuleFileName[MAX_PATH+20];
  105. if (0 < ::GetModuleFileName(
  106. AfxGetInstanceHandle(),
  107. achModuleFileName,
  108. sizeof(achModuleFileName)/sizeof(TCHAR) ))
  109. {
  110. CString strNameIndirect;
  111. strNameIndirect.Format( _T("@%s,-%d"),
  112. achModuleFileName,
  113. residSnapinName );
  114. regkeySnapin.SetString( _T("NameStringIndirect"),
  115. strNameIndirect );
  116. }
  117. }
  118. catch (COleException* e)
  119. {
  120. ASSERT(FALSE);
  121. e->Delete();
  122. return SELFREG_E_CLASS;
  123. }
  124. return hr;
  125. }