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.

180 lines
4.4 KiB

  1. /*****************************************************************************\
  2. FILE: dllreg.cpp
  3. DESCRIPTION:
  4. Register selfreg.inf, which exists in our resource.
  5. BryanSt 4/4/2000 (Bryan Starbuck)
  6. Copyright (C) Microsoft Corp 2000-2000. All rights reserved.
  7. \*****************************************************************************/
  8. #include "priv.h"
  9. #include <advpub.h>
  10. #include <comcat.h>
  11. #include <theme.h> // For LIBID_Theme
  12. extern CComModule _Module;
  13. // helper macros
  14. // ADVPACK will return E_UNEXPECTED if you try to uninstall (which does a registry restore)
  15. // on an INF section that was never installed. We uninstall sections that may never have
  16. // been installed, so this MACRO will quiet these errors.
  17. #define QuietInstallNoOp(hr) ((E_UNEXPECTED == hr) ? S_OK : hr)
  18. BOOL UnregisterTypeLibrary(const CLSID* piidLibrary)
  19. {
  20. TCHAR szScratch[GUIDSTR_MAX];
  21. HKEY hk;
  22. BOOL fResult = FALSE;
  23. // convert the libid into a string.
  24. //
  25. SHStringFromGUID(*piidLibrary, szScratch, ARRAYSIZE(szScratch));
  26. if (RegOpenKey(HKEY_CLASSES_ROOT, TEXT("TypeLib"), &hk) == ERROR_SUCCESS) {
  27. fResult = RegDeleteKey(hk, szScratch);
  28. RegCloseKey(hk);
  29. }
  30. return fResult;
  31. }
  32. HRESULT MyRegTypeLib(void)
  33. {
  34. HRESULT hr = S_OK;
  35. ITypeLib *pTypeLib;
  36. DWORD dwPathLen;
  37. TCHAR szTmp[MAX_PATH];
  38. #ifdef UNICODE
  39. WCHAR *pwsz = szTmp;
  40. #else
  41. WCHAR pwsz[MAX_PATH];
  42. #endif
  43. // Load and register our type library.
  44. //
  45. dwPathLen = GetModuleFileName(HINST_THISDLL, szTmp, ARRAYSIZE(szTmp));
  46. #ifndef UNICODE
  47. if (SHAnsiToUnicode(szTmp, pwsz, MAX_PATH))
  48. #endif
  49. {
  50. hr = LoadTypeLib(pwsz, &pTypeLib);
  51. if (SUCCEEDED(hr))
  52. {
  53. // call the unregister type library as we had some old junk that
  54. // was registered by a previous version of OleAut32, which is now causing
  55. // the current version to not work on NT...
  56. UnregisterTypeLibrary(&LIBID_Theme);
  57. hr = RegisterTypeLib(pTypeLib, pwsz, NULL);
  58. if (FAILED(hr))
  59. {
  60. TraceMsg(TF_WARNING, "RegisterTypeLib failed (%x)", hr);
  61. }
  62. pTypeLib->Release();
  63. }
  64. else
  65. {
  66. TraceMsg(TF_WARNING, "LoadTypeLib failed (%x)", hr);
  67. }
  68. }
  69. #ifndef UNICODE
  70. else {
  71. hr = E_FAIL;
  72. }
  73. #endif
  74. return hr;
  75. }
  76. /*----------------------------------------------------------
  77. Purpose: Calls the ADVPACK entry-point which executes an inf
  78. file section.
  79. Returns:
  80. Cond: --
  81. */
  82. HRESULT CallRegInstall(LPSTR szSection)
  83. {
  84. HRESULT hr = E_FAIL;
  85. HINSTANCE hinstAdvPack = LoadLibrary(TEXT("ADVPACK.DLL"));
  86. if (hinstAdvPack)
  87. {
  88. REGINSTALL pfnri = (REGINSTALL)GetProcAddress(hinstAdvPack, "RegInstall");
  89. if (pfnri)
  90. {
  91. char szIEPath[MAX_PATH];
  92. STRENTRY seReg[] = {
  93. { "NO_LONGER_USED", szIEPath },
  94. // These two NT-specific entries must be at the end
  95. { "25", "%SystemRoot%" },
  96. { "11", "%SystemRoot%\\system32" },
  97. };
  98. STRTABLE stReg = { ARRAYSIZE(seReg) - 2, seReg };
  99. szIEPath[0] = 0;
  100. hr = pfnri(HINST_THISDLL, szSection, &stReg);
  101. }
  102. FreeLibrary(hinstAdvPack);
  103. }
  104. return hr;
  105. }
  106. STDAPI DllRegisterServer(void)
  107. {
  108. HRESULT hr;
  109. HINSTANCE hinstAdvPack = LoadLibrary(TEXT("ADVPACK.DLL"));
  110. hr = CallRegInstall("DLL_RegInstall");
  111. //---- do this even if error occured ----
  112. MyRegTypeLib();
  113. if (hinstAdvPack)
  114. FreeLibrary(hinstAdvPack);
  115. return hr;
  116. }
  117. STDAPI DllUnregisterServer(void)
  118. {
  119. HRESULT hr;
  120. // UnInstall the registry values
  121. hr = CallRegInstall("DLL_RegUnInstall");
  122. UnregisterTypeLibrary(&LIBID_Theme);
  123. return hr;
  124. }
  125. /*----------------------------------------------------------
  126. Purpose: Install/uninstall user settings
  127. Description: Note that this function has special error handling.
  128. The function will keep hrExternal with the worse error
  129. but will only stop executing util the internal error (hr)
  130. gets really bad. This is because we need the external
  131. error to catch incorrectly authored INFs but the internal
  132. error to be robust in attempting to install other INF sections
  133. even if one doesn't make it.
  134. */
  135. STDAPI DllInstall(BOOL bInstall, LPCWSTR pszCmdLine)
  136. {
  137. return S_OK;
  138. }