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.

127 lines
3.1 KiB

  1. // CertWiz.cpp : Implementation of CCertWizApp and DLL registration.
  2. #include "stdafx.h"
  3. #include "CertWiz.h"
  4. #ifdef _DEBUG
  5. #define new DEBUG_NEW
  6. #undef THIS_FILE
  7. static char THIS_FILE[] = __FILE__;
  8. #endif
  9. CCertWizApp NEAR theApp;
  10. const GUID CDECL BASED_CODE _tlid =
  11. { 0xd4be862f, 0xc85, 0x11d2, { 0x91, 0xb1, 0, 0xc0, 0x4f, 0x8c, 0x87, 0x61 } };
  12. const WORD _wVerMajor = 1;
  13. const WORD _wVerMinor = 0;
  14. const TCHAR szRegistryKey[] = _T("SOFTWARE\\Microsoft\\InetMgr");
  15. const TCHAR szWizardKey[] = _T("CertWiz");
  16. ///////////////////////////////////////////////////////////////////////////
  17. // CCertWizApp::InitInstance - DLL initialization
  18. BOOL CCertWizApp::InitInstance()
  19. {
  20. BOOL bInit = COleControlModule::InitInstance();
  21. if (bInit)
  22. {
  23. AfxEnableControlContainer();
  24. InitCommonDll();
  25. CString sz;
  26. // set the name of the application correctly
  27. sz.LoadString(IDS_CERTWIZ);
  28. // free the existing name, and copy in the new one
  29. free((void*)m_pszAppName);
  30. m_pszAppName = _tcsdup(sz);
  31. GetOutputDebugFlag();
  32. }
  33. return bInit;
  34. }
  35. ////////////////////////////////////////////////////////////////////////////
  36. // CCertWizApp::ExitInstance - DLL termination
  37. int CCertWizApp::ExitInstance()
  38. {
  39. // TODO: Add your own module termination code here.
  40. return COleControlModule::ExitInstance();
  41. }
  42. HKEY
  43. CCertWizApp::RegOpenKeyWizard()
  44. {
  45. HKEY hKey = NULL;
  46. CString strKey;
  47. GetRegistryPath(strKey);
  48. VERIFY(ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, strKey, 0, KEY_ALL_ACCESS, &hKey));
  49. return hKey;
  50. }
  51. void
  52. CCertWizApp::GetRegistryPath(CString& str)
  53. {
  54. str = szRegistryKey;
  55. str += _T("\\");
  56. str += szWizardKey;
  57. }
  58. /////////////////////////////////////////////////////////////////////////////
  59. // DllRegisterServer - Adds entries to the system registry
  60. STDAPI DllRegisterServer(void)
  61. {
  62. AFX_MANAGE_STATE(_afxModuleAddrThis);
  63. if (!AfxOleRegisterTypeLib(AfxGetInstanceHandle(), _tlid))
  64. return ResultFromScode(SELFREG_E_TYPELIB);
  65. if (!COleObjectFactoryEx::UpdateRegistryAll(TRUE))
  66. return ResultFromScode(SELFREG_E_CLASS);
  67. HKEY hKey;
  68. int rc = NOERROR;
  69. if (ERROR_SUCCESS == (rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  70. szRegistryKey, 0, KEY_CREATE_SUB_KEY, &hKey)))
  71. {
  72. HKEY hWizardKey;
  73. if (ERROR_SUCCESS == (rc = RegCreateKey(hKey, szWizardKey, &hWizardKey)))
  74. {
  75. RegCloseKey(hWizardKey);
  76. }
  77. RegCloseKey(hKey);
  78. }
  79. return rc;
  80. }
  81. /////////////////////////////////////////////////////////////////////////////
  82. // DllUnregisterServer - Removes entries from the system registry
  83. STDAPI DllUnregisterServer(void)
  84. {
  85. AFX_MANAGE_STATE(_afxModuleAddrThis);
  86. if (!AfxOleUnregisterTypeLib(_tlid, _wVerMajor, _wVerMinor))
  87. return ResultFromScode(SELFREG_E_TYPELIB);
  88. if (!COleObjectFactoryEx::UpdateRegistryAll(FALSE))
  89. return ResultFromScode(SELFREG_E_CLASS);
  90. // remove CertWiz data from the Registry
  91. HKEY hKey;
  92. if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  93. szRegistryKey, 0, KEY_ALL_ACCESS, &hKey))
  94. {
  95. RegDeleteKey(hKey, szWizardKey);
  96. RegCloseKey(hKey);
  97. }
  98. return NOERROR;
  99. }