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.

163 lines
4.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. CString strProvider, strVersion;
  61. if ( !strProvider.LoadString(residProvider)
  62. || !strVersion.LoadString(residVersion)
  63. )
  64. {
  65. ASSERT(FALSE);
  66. return SELFREG_E_CLASS;
  67. }
  68. return RegisterSnapin( regkeySnapins,
  69. pszSnapinGUID,
  70. bstrPrimaryNodetype,
  71. residSnapinName,
  72. strProvider,
  73. strVersion,
  74. fStandalone,
  75. pszAboutGUID,
  76. aiNodetypeIndexes,
  77. cNodetypeIndexes);
  78. }
  79. HRESULT RegisterSnapin(
  80. AMC::CRegKey& regkeySnapins,
  81. LPCTSTR pszSnapinGUID,
  82. BSTR bstrPrimaryNodetype,
  83. UINT residSnapinName,
  84. const CString& szProvider,
  85. const CString& szVersion,
  86. bool fStandalone,
  87. LPCTSTR pszAboutGUID,
  88. int* aiNodetypeIndexes,
  89. int cNodetypeIndexes )
  90. {
  91. HRESULT hr = S_OK;
  92. try
  93. {
  94. AMC::CRegKey regkeySnapin;
  95. CString strSnapinName;
  96. if ( !strSnapinName.LoadString(residSnapinName)
  97. )
  98. {
  99. ASSERT(FALSE);
  100. return SELFREG_E_CLASS;
  101. }
  102. regkeySnapin.CreateKeyEx( regkeySnapins, pszSnapinGUID );
  103. if (NULL != bstrPrimaryNodetype)
  104. {
  105. regkeySnapin.SetString( _T("NodeType"), bstrPrimaryNodetype );
  106. }
  107. regkeySnapin.SetString( _T("NameString"), strSnapinName );
  108. regkeySnapin.SetString( _T("Provider"), szProvider );
  109. regkeySnapin.SetString( _T("Version"), szVersion );
  110. if (fStandalone)
  111. {
  112. AMC::CRegKey regkeyStandalone;
  113. regkeyStandalone.CreateKeyEx( regkeySnapin, _T("StandAlone") );
  114. }
  115. if (NULL != pszAboutGUID)
  116. {
  117. regkeySnapin.SetString( _T("About"), pszAboutGUID );
  118. }
  119. if ( NULL != aiNodetypeIndexes && 0 != cNodetypeIndexes )
  120. {
  121. hr = RegisterNodetypes(
  122. regkeySnapin,
  123. aiNodetypeIndexes,
  124. cNodetypeIndexes );
  125. }
  126. //
  127. // JonN 4/25/00
  128. // 100624: MUI: MMC: Shared Folders snap-in stores
  129. // its display information in the registry
  130. //
  131. // MMC now supports NameStringIndirect
  132. //
  133. TCHAR achModuleFileName[MAX_PATH+20];
  134. if (0 < ::GetModuleFileName(
  135. AfxGetInstanceHandle(),
  136. achModuleFileName,
  137. (sizeof(achModuleFileName)/sizeof(TCHAR)) - 1 ))
  138. {
  139. achModuleFileName[MAX_PATH+19] = _T('\0'); // 616500-2002/05/07-JonN
  140. CString strNameIndirect;
  141. strNameIndirect.Format( _T("@%s,-%d"),
  142. achModuleFileName,
  143. residSnapinName );
  144. regkeySnapin.SetString( _T("NameStringIndirect"),
  145. strNameIndirect );
  146. }
  147. }
  148. catch (COleException* e)
  149. {
  150. ASSERT(FALSE);
  151. e->Delete();
  152. return SELFREG_E_CLASS;
  153. }
  154. return hr;
  155. }