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.

188 lines
5.4 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. return CWinApp::InitInstance();
  38. }
  39. int CSchmMgmtApp::ExitInstance()
  40. {
  41. _Module.Term();
  42. return CWinApp::ExitInstance();
  43. }
  44. /////////////////////////////////////////////////////////////////////////////
  45. // Used to determine whether the DLL can be unloaded by OLE
  46. STDAPI DllCanUnloadNow(void)
  47. {
  48. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  49. return (AfxDllCanUnloadNow()==S_OK && _Module.GetLockCount()==0) ? S_OK : S_FALSE;
  50. }
  51. /////////////////////////////////////////////////////////////////////////////
  52. // Returns a class factory to create an object of the requested type
  53. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  54. {
  55. return _Module.GetClassObject(rclsid, riid, ppv);
  56. }
  57. /////////////////////////////////////////////////////////////////////////////
  58. // DllRegisterServer - Adds entries to the system registry
  59. STDAPI DllRegisterServer( void ) {
  60. MFC_TRY;
  61. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  62. HRESULT hRes = S_OK;
  63. CString Name, Microsoft, About, Provider, Version, VerString;
  64. Name.LoadString(IDS_REGSERV_NAME);
  65. Microsoft.LoadString(IDS_REGSERV_MICROSOFT);
  66. About.LoadString(IDS_REGSERV_ABOUT);
  67. Provider.LoadString(IDS_REGSERV_PROVIDER);
  68. Version.LoadString(IDS_REGSERV_VERSION);
  69. VerString.LoadString(IDS_SNAPINABOUT_VERSION);
  70. //
  71. // registers object, typelib and all interfaces in typelib
  72. //
  73. hRes = _Module.RegisterServer(FALSE);
  74. try {
  75. AMC::CRegKey regkeySnapins;
  76. BOOL fFound = regkeySnapins.OpenKeyEx( HKEY_LOCAL_MACHINE, SNAPINS_KEY );
  77. if ( !fFound ) {
  78. ASSERT(FALSE);
  79. return SELFREG_E_CLASS;
  80. }
  81. {
  82. AMC::CRegKey regkeySchmMgmtSnapin;
  83. CString strGUID;
  84. HRESULT hr = GuidToCString(OUT &strGUID, CLSID_SchmMgmt );
  85. if ( FAILED(hr) ) {
  86. ASSERT(FALSE);
  87. return SELFREG_E_CLASS;
  88. }
  89. regkeySchmMgmtSnapin.CreateKeyEx( regkeySnapins, strGUID );
  90. regkeySchmMgmtSnapin.SetString( g_szNodeType, g_aNodetypeGuids[SCHMMGMT_SCHMMGMT].bstr );
  91. regkeySchmMgmtSnapin.SetString( g_szNameString, Name );
  92. hr = GuidToCString(OUT &strGUID, CLSID_SchemaManagementAbout );
  93. if ( FAILED(hr) ) {
  94. ASSERT(FALSE);
  95. return SELFREG_E_CLASS;
  96. }
  97. regkeySchmMgmtSnapin.SetString( About, strGUID );
  98. regkeySchmMgmtSnapin.SetString( Provider, Microsoft );
  99. regkeySchmMgmtSnapin.SetString( Version, VerString );
  100. AMC::CRegKey regkeySchmMgmtStandalone;
  101. regkeySchmMgmtStandalone.CreateKeyEx( regkeySchmMgmtSnapin, g_szStandAlone );
  102. AMC::CRegKey regkeyMyNodeTypes;
  103. regkeyMyNodeTypes.CreateKeyEx( regkeySchmMgmtSnapin, g_szNodeTypes );
  104. AMC::CRegKey regkeyMyNodeType;
  105. for (int i = SCHMMGMT_SCHMMGMT; i < SCHMMGMT_NUMTYPES; i++)
  106. {
  107. regkeyMyNodeType.CreateKeyEx( regkeyMyNodeTypes, g_aNodetypeGuids[i].bstr );
  108. regkeyMyNodeType.CloseKey();
  109. }
  110. }
  111. AMC::CRegKey regkeyNodeTypes;
  112. fFound = regkeyNodeTypes.OpenKeyEx( HKEY_LOCAL_MACHINE, NODE_TYPES_KEY );
  113. if ( !fFound )
  114. {
  115. ASSERT(FALSE);
  116. return SELFREG_E_CLASS;
  117. }
  118. AMC::CRegKey regkeyNodeType;
  119. for (int i = SCHMMGMT_SCHMMGMT; i < SCHMMGMT_NUMTYPES; i++)
  120. {
  121. regkeyNodeType.CreateKeyEx( regkeyNodeTypes, g_aNodetypeGuids[i].bstr );
  122. regkeyNodeType.CloseKey();
  123. }
  124. }
  125. catch (COleException* e)
  126. {
  127. ASSERT(FALSE);
  128. e->Delete();
  129. return SELFREG_E_CLASS;
  130. }
  131. return hRes;
  132. MFC_CATCH;
  133. }
  134. /////////////////////////////////////////////////////////////////////////////
  135. // DllUnregisterServer - Removes entries from the system registry
  136. STDAPI DllUnregisterServer(void)
  137. {
  138. _Module.UnregisterServer();
  139. return S_OK;
  140. }