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.

197 lines
5.7 KiB

  1. //
  2. // SchmMgmt.cpp : Implementation of DLL Exports.
  3. // Cory West
  4. #include "stdafx.h"
  5. #include "resource.h"
  6. #include "initguid.h"
  7. #include "schmmgmt.h"
  8. #include "regkey.h" // AMC::CRegKey
  9. #include "strings.h" // SNAPINS_KEY
  10. #include "macros.h" // MFC_TRY/MFC_CATCH
  11. #include "stdutils.h" // g_aNodetypeGuids
  12. #include "cookie.h"
  13. #include "compdata.h" // ComponentData
  14. #include "about.h" // CSchemaMgmtAbout
  15. USE_HANDLE_MACROS("SchmMgmt(SchmMgmt.cpp)")
  16. // Snapin CLSID - {632cccf4-cbed-11d0-9c16-00c04fd8d86e}
  17. const CLSID CLSID_SchmMgmt =
  18. {0x632cccf4, 0xcbed, 0x11d0, {0x9c, 0x16, 0x00, 0xc0, 0x4f, 0xd8, 0xd8, 0x6e}};
  19. // Snapin about CLSID - {333fe3fb-0a9d-11d1-bb10-00c04fc9a3a3}
  20. const CLSID CLSID_SchemaManagementAbout =
  21. {0x333fe3fb, 0x0a9d, 0x11d1, {0xbb, 0x10, 0x00, 0xc0, 0x4f, 0xc9, 0xa3, 0xa3}};
  22. CComModule _Module;
  23. BEGIN_OBJECT_MAP(ObjectMap)
  24. OBJECT_ENTRY(CLSID_SchmMgmt, ComponentData)
  25. OBJECT_ENTRY(CLSID_SchemaManagementAbout, CSchemaMgmtAbout)
  26. END_OBJECT_MAP()
  27. class CSchmMgmtApp : public CWinApp
  28. {
  29. public:
  30. virtual BOOL InitInstance();
  31. virtual int ExitInstance();
  32. };
  33. CSchmMgmtApp theApp;
  34. BOOL CSchmMgmtApp::InitInstance()
  35. {
  36. _Module.Init(ObjectMap, m_hInstance);
  37. // Add theming support
  38. SHFusionInitializeFromModuleID(m_hInstance, 2);
  39. return CWinApp::InitInstance();
  40. }
  41. int CSchmMgmtApp::ExitInstance()
  42. {
  43. // Theming support
  44. SHFusionUninitialize();
  45. _Module.Term();
  46. return CWinApp::ExitInstance();
  47. }
  48. /////////////////////////////////////////////////////////////////////////////
  49. // Used to determine whether the DLL can be unloaded by OLE
  50. STDAPI DllCanUnloadNow(void)
  51. {
  52. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  53. return (AfxDllCanUnloadNow()==S_OK && _Module.GetLockCount()==0) ? S_OK : S_FALSE;
  54. }
  55. /////////////////////////////////////////////////////////////////////////////
  56. // Returns a class factory to create an object of the requested type
  57. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  58. {
  59. return _Module.GetClassObject(rclsid, riid, ppv);
  60. }
  61. /////////////////////////////////////////////////////////////////////////////
  62. // DllRegisterServer - Adds entries to the system registry
  63. STDAPI DllRegisterServer( void ) {
  64. MFC_TRY;
  65. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  66. HRESULT hRes = S_OK;
  67. CString Name, Microsoft, About, Provider, Version, VerString;
  68. Name.LoadString(IDS_REGSERV_NAME);
  69. Microsoft.LoadString(IDS_REGSERV_MICROSOFT);
  70. About.LoadString(IDS_REGSERV_ABOUT);
  71. Provider.LoadString(IDS_REGSERV_PROVIDER);
  72. Version.LoadString(IDS_REGSERV_VERSION);
  73. VerString = IDS_SNAPINABOUT_VERSION;
  74. //
  75. // registers object, typelib and all interfaces in typelib
  76. //
  77. hRes = _Module.RegisterServer(FALSE);
  78. try {
  79. AMC::CRegKey regkeySnapins;
  80. BOOL fFound = regkeySnapins.OpenKeyEx( HKEY_LOCAL_MACHINE, SNAPINS_KEY );
  81. if ( !fFound ) {
  82. ASSERT(FALSE);
  83. return SELFREG_E_CLASS;
  84. }
  85. {
  86. AMC::CRegKey regkeySchmMgmtSnapin;
  87. CString strGUID;
  88. HRESULT hr = GuidToCString(OUT &strGUID, CLSID_SchmMgmt );
  89. if ( FAILED(hr) ) {
  90. ASSERT(FALSE);
  91. return SELFREG_E_CLASS;
  92. }
  93. regkeySchmMgmtSnapin.CreateKeyEx( regkeySnapins, strGUID );
  94. regkeySchmMgmtSnapin.SetString( g_szNodeType, g_aNodetypeGuids[SCHMMGMT_SCHMMGMT].bstr );
  95. regkeySchmMgmtSnapin.SetString( g_szNameString, Name );
  96. hr = GuidToCString(OUT &strGUID, CLSID_SchemaManagementAbout );
  97. if ( FAILED(hr) ) {
  98. ASSERT(FALSE);
  99. return SELFREG_E_CLASS;
  100. }
  101. regkeySchmMgmtSnapin.SetString( About, strGUID );
  102. regkeySchmMgmtSnapin.SetString( Provider, Microsoft );
  103. regkeySchmMgmtSnapin.SetString( Version, VerString );
  104. AMC::CRegKey regkeySchmMgmtStandalone;
  105. regkeySchmMgmtStandalone.CreateKeyEx( regkeySchmMgmtSnapin, g_szStandAlone );
  106. AMC::CRegKey regkeyMyNodeTypes;
  107. regkeyMyNodeTypes.CreateKeyEx( regkeySchmMgmtSnapin, g_szNodeTypes );
  108. AMC::CRegKey regkeyMyNodeType;
  109. for (int i = SCHMMGMT_SCHMMGMT; i < SCHMMGMT_NUMTYPES; i++)
  110. {
  111. regkeyMyNodeType.CreateKeyEx( regkeyMyNodeTypes, g_aNodetypeGuids[i].bstr );
  112. regkeyMyNodeType.CloseKey();
  113. }
  114. }
  115. AMC::CRegKey regkeyNodeTypes;
  116. fFound = regkeyNodeTypes.OpenKeyEx( HKEY_LOCAL_MACHINE, NODE_TYPES_KEY );
  117. if ( !fFound )
  118. {
  119. ASSERT(FALSE);
  120. return SELFREG_E_CLASS;
  121. }
  122. AMC::CRegKey regkeyNodeType;
  123. for (int i = SCHMMGMT_SCHMMGMT; i < SCHMMGMT_NUMTYPES; i++)
  124. {
  125. regkeyNodeType.CreateKeyEx( regkeyNodeTypes, g_aNodetypeGuids[i].bstr );
  126. regkeyNodeType.CloseKey();
  127. }
  128. }
  129. catch (COleException* e)
  130. {
  131. ASSERT(FALSE);
  132. e->Delete();
  133. return SELFREG_E_CLASS;
  134. }
  135. return hRes;
  136. MFC_CATCH;
  137. }
  138. /////////////////////////////////////////////////////////////////////////////
  139. // DllUnregisterServer - Removes entries from the system registry
  140. STDAPI DllUnregisterServer(void)
  141. {
  142. _Module.UnregisterServer();
  143. return S_OK;
  144. }