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.

125 lines
3.0 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. }
  32. return bInit;
  33. }
  34. ////////////////////////////////////////////////////////////////////////////
  35. // CCertWizApp::ExitInstance - DLL termination
  36. int CCertWizApp::ExitInstance()
  37. {
  38. // TODO: Add your own module termination code here.
  39. return COleControlModule::ExitInstance();
  40. }
  41. HKEY
  42. CCertWizApp::RegOpenKeyWizard()
  43. {
  44. HKEY hKey = NULL;
  45. CString strKey;
  46. GetRegistryPath(strKey);
  47. VERIFY(ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, strKey, 0, KEY_ALL_ACCESS, &hKey));
  48. return hKey;
  49. }
  50. void
  51. CCertWizApp::GetRegistryPath(CString& str)
  52. {
  53. str = szRegistryKey;
  54. str += _T("\\");
  55. str += szWizardKey;
  56. }
  57. /////////////////////////////////////////////////////////////////////////////
  58. // DllRegisterServer - Adds entries to the system registry
  59. STDAPI DllRegisterServer(void)
  60. {
  61. AFX_MANAGE_STATE(_afxModuleAddrThis);
  62. if (!AfxOleRegisterTypeLib(AfxGetInstanceHandle(), _tlid))
  63. return ResultFromScode(SELFREG_E_TYPELIB);
  64. if (!COleObjectFactoryEx::UpdateRegistryAll(TRUE))
  65. return ResultFromScode(SELFREG_E_CLASS);
  66. HKEY hKey;
  67. int rc = NOERROR;
  68. if (ERROR_SUCCESS == (rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  69. szRegistryKey, 0, KEY_CREATE_SUB_KEY, &hKey)))
  70. {
  71. HKEY hWizardKey;
  72. if (ERROR_SUCCESS == (rc = RegCreateKey(hKey, szWizardKey, &hWizardKey)))
  73. {
  74. RegCloseKey(hWizardKey);
  75. }
  76. RegCloseKey(hKey);
  77. }
  78. return rc;
  79. }
  80. /////////////////////////////////////////////////////////////////////////////
  81. // DllUnregisterServer - Removes entries from the system registry
  82. STDAPI DllUnregisterServer(void)
  83. {
  84. AFX_MANAGE_STATE(_afxModuleAddrThis);
  85. if (!AfxOleUnregisterTypeLib(_tlid, _wVerMajor, _wVerMinor))
  86. return ResultFromScode(SELFREG_E_TYPELIB);
  87. if (!COleObjectFactoryEx::UpdateRegistryAll(FALSE))
  88. return ResultFromScode(SELFREG_E_CLASS);
  89. // remove CertWiz data from the Registry
  90. HKEY hKey;
  91. if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  92. szRegistryKey, 0, KEY_ALL_ACCESS, &hKey))
  93. {
  94. RegDeleteKey(hKey, szWizardKey);
  95. RegCloseKey(hKey);
  96. }
  97. return NOERROR;
  98. }