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.

154 lines
4.0 KiB

  1. // MyComput.cpp : Implementation of DLL Exports.
  2. #include "stdafx.h"
  3. #include "resource.h"
  4. #include "initguid.h"
  5. #include "MyComput.h"
  6. #include "regkey.h" // AMC::CRegKey
  7. #include "strings.h" // SNAPINS_KEY
  8. #include "guidhelp.h" // GuidToCString
  9. #include "macros.h" // MFC_TRY/MFC_CATCH
  10. #include "stdutils.h" // g_aNodetypeGuids
  11. #include "MyComput_i.c"
  12. #include "about.h" // CComputerMgmtAbout
  13. #include "compdata.h" // CMyComputerComponentData
  14. #include "snapreg.h" // RegisterSnapin
  15. USE_HANDLE_MACROS("MYCOMPUT(MyComput.cpp)") \
  16. CComModule _Module;
  17. BEGIN_OBJECT_MAP(ObjectMap)
  18. OBJECT_ENTRY(CLSID_MyComputer, CMyComputerComponentData)
  19. OBJECT_ENTRY(CLSID_ComputerManagementAbout, CComputerMgmtAbout)
  20. END_OBJECT_MAP()
  21. class CMyComputApp : public CWinApp
  22. {
  23. public:
  24. virtual BOOL InitInstance();
  25. virtual int ExitInstance();
  26. };
  27. CMyComputApp theApp;
  28. BOOL CMyComputApp::InitInstance()
  29. {
  30. _Module.Init(ObjectMap, m_hInstance);
  31. return CWinApp::InitInstance();
  32. }
  33. int CMyComputApp::ExitInstance()
  34. {
  35. _Module.Term();
  36. return CWinApp::ExitInstance();
  37. }
  38. /////////////////////////////////////////////////////////////////////////////
  39. // Used to determine whether the DLL can be unloaded by OLE
  40. STDAPI DllCanUnloadNow(void)
  41. {
  42. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  43. return (AfxDllCanUnloadNow()==S_OK && _Module.GetLockCount()==0) ? S_OK : S_FALSE;
  44. }
  45. /////////////////////////////////////////////////////////////////////////////
  46. // Returns a class factory to create an object of the requested type
  47. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  48. {
  49. return _Module.GetClassObject(rclsid, riid, ppv);
  50. }
  51. /////////////////////////////////////////////////////////////////////////////
  52. // DllRegisterServer - Adds entries to the system registry
  53. STDAPI DllRegisterServer(void)
  54. {
  55. MFC_TRY;
  56. HRESULT hr = S_OK;
  57. // registers object, typelib and all interfaces in typelib
  58. hr = _Module.RegisterServer(TRUE);
  59. CString strMyComputerCLSID, strMyComputerAboutCLSID;
  60. if ( FAILED(hr = GuidToCString( &strMyComputerCLSID, CLSID_MyComputer ))
  61. || FAILED(hr = GuidToCString( &strMyComputerAboutCLSID, CLSID_ComputerManagementAbout ))
  62. )
  63. {
  64. ASSERT(FALSE && "GuidToCString() failure");
  65. return SELFREG_E_CLASS;
  66. }
  67. try
  68. {
  69. AMC::CRegKey regkeySnapins;
  70. BOOL fFound = regkeySnapins.OpenKeyEx( HKEY_LOCAL_MACHINE, SNAPINS_KEY );
  71. if ( !fFound )
  72. {
  73. ASSERT(FALSE && "DllRegisterServer() - Unable to open key from registry.");
  74. return SELFREG_E_CLASS;
  75. }
  76. static int mycomput_types[4] =
  77. { MYCOMPUT_COMPUTER,
  78. MYCOMPUT_SYSTEMTOOLS,
  79. MYCOMPUT_SERVERAPPS,
  80. MYCOMPUT_STORAGE };
  81. hr = RegisterSnapin( regkeySnapins,
  82. strMyComputerCLSID,
  83. g_aNodetypeGuids[MYCOMPUT_COMPUTER].bstr,
  84. IDS_REGISTER_MYCOMPUT,
  85. IDS_SNAPINABOUT_PROVIDER,
  86. IDS_SNAPINABOUT_VERSION,
  87. true,
  88. strMyComputerAboutCLSID,
  89. mycomput_types,
  90. 4 );
  91. if ( FAILED(hr) )
  92. {
  93. ASSERT(FALSE);
  94. return SELFREG_E_CLASS;
  95. }
  96. AMC::CRegKey regkeyNodeTypes;
  97. fFound = regkeyNodeTypes.OpenKeyEx( HKEY_LOCAL_MACHINE, NODE_TYPES_KEY );
  98. if ( !fFound )
  99. {
  100. ASSERT(FALSE);
  101. return SELFREG_E_CLASS;
  102. }
  103. AMC::CRegKey regkeyNodeType;
  104. for (int i = MYCOMPUT_COMPUTER; i < MYCOMPUT_NUMTYPES; i++)
  105. {
  106. regkeyNodeType.CreateKeyEx( regkeyNodeTypes, g_aNodetypeGuids[i].bstr );
  107. regkeyNodeType.CloseKey();
  108. }
  109. }
  110. catch (COleException* e)
  111. {
  112. ASSERT(FALSE);
  113. e->Delete();
  114. return SELFREG_E_CLASS;
  115. }
  116. return hr;
  117. MFC_CATCH;
  118. }
  119. /////////////////////////////////////////////////////////////////////////////
  120. // DllUnregisterServer - Removes entries from the system registry
  121. STDAPI DllUnregisterServer(void)
  122. {
  123. // ISSUE-2002/02/27-JonN Should probably remove MMC entries as well
  124. _Module.UnregisterServer();
  125. return S_OK;
  126. }