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.

123 lines
3.7 KiB

  1. //*** uassist.cpp -- User Assist helpers (retail and debug)
  2. //
  3. // DESCRIPTION
  4. // this file has the shared-source 'master' implementation. it is
  5. // #included in each DLL that uses it. NEEDED because of ENTERCRITICAL
  6. // as stocklib.dll does not have a critical section in it.
  7. //
  8. // clients do something like:
  9. // #include "priv.h" // for types, ASSERT, DM_*, DF_*, etc.
  10. // #include "../lib/uassist.cpp"
  11. //
  12. // we cache the UAssist object and provide thunks for 'safe' access to it.
  13. #include "uemapp.h"
  14. #define DM_UASSIST 0
  15. IUserAssist *g_uempUa; // 0:uninit, -1:failed, o.w.:cached obj
  16. //*** GetUserAssist -- get (and create) cached UAssist object
  17. //
  18. IUserAssist *GetUserAssist()
  19. {
  20. HRESULT hr;
  21. IUserAssist * pua = NULL;
  22. if (g_uempUa == 0)
  23. {
  24. // re: CLSCTX_NO_CODE_DOWNLOAD
  25. // an ('impossible') failed CCI of UserAssist is horrendously slow.
  26. // e.g. click on the start menu, wait 10 seconds before it pops up.
  27. // we'd rather fail than hose perf like this, plus this class should
  28. // never be remote.
  29. // FEATURE: there must be a better way to tell if CLSCTX_NO_CODE_DOWNLOAD
  30. // is supported, i've sent mail to 'com' to find out...
  31. DWORD dwFlags = staticIsOS(OS_WIN2000ORGREATER) ? (CLSCTX_INPROC|CLSCTX_NO_CODE_DOWNLOAD) : CLSCTX_INPROC;
  32. hr = THR(CoCreateInstance(CLSID_UserAssist, NULL, dwFlags, IID_IUserAssist, (void**)&pua));
  33. ASSERT(SUCCEEDED(hr) || pua == NULL); // follow COM rules
  34. if (pua)
  35. {
  36. HINSTANCE hInst;
  37. hInst = SHPinDllOfCLSID(&CLSID_UserAssist); // cached across threads
  38. // we're toast if this fails!!! (but happily, that's 'impossible')
  39. // e.g. during logon when grpconv.exe is ShellExec'ed, we do
  40. // a GetUserAssist, which caches a ptr to browseui's singleton
  41. // object. then when the ShellExec returns, we do CoUninit,
  42. // which would free up the (non-pinned) browseui.dll. then
  43. // a later use of the cache would go off into space.
  44. }
  45. ENTERCRITICAL;
  46. if (g_uempUa == 0) {
  47. g_uempUa = pua; // xfer refcnt (if any)
  48. if (!pua) {
  49. // mark it failed so we won't try any more
  50. g_uempUa = (IUserAssist *)-1;
  51. }
  52. pua = NULL;
  53. }
  54. LEAVECRITICAL;
  55. if (pua)
  56. pua->Release();
  57. TraceMsg(DM_UASSIST, "sl.gua: pua=0x%x g_uempUa=%x", pua, g_uempUa);
  58. }
  59. return (g_uempUa == (IUserAssist *)-1) ? 0 : g_uempUa;
  60. }
  61. extern "C"
  62. BOOL UEMIsLoaded()
  63. {
  64. BOOL fRet;
  65. fRet = GetModuleHandle(TEXT("ole32.dll")) &&
  66. GetModuleHandle(TEXT("browseui.dll"));
  67. return fRet;
  68. }
  69. //*** UEMFireEvent, QueryEvent, SetEvent -- 'safe' thunks
  70. // DESCRIPTION
  71. // call these so don't have to worry about cache or whether Uassist object
  72. // even was successfully created.
  73. extern "C"
  74. HRESULT UEMFireEvent(const GUID *pguidGrp, int eCmd, DWORD dwFlags, WPARAM wParam, LPARAM lParam)
  75. {
  76. HRESULT hr = E_FAIL;
  77. IUserAssist *pua;
  78. pua = GetUserAssist();
  79. if (pua) {
  80. hr = pua->FireEvent(pguidGrp, eCmd, dwFlags, wParam, lParam);
  81. }
  82. return hr;
  83. }
  84. extern "C"
  85. HRESULT UEMQueryEvent(const GUID *pguidGrp, int eCmd, WPARAM wParam, LPARAM lParam, LPUEMINFO pui)
  86. {
  87. HRESULT hr = E_FAIL;
  88. IUserAssist *pua;
  89. pua = GetUserAssist();
  90. if (pua) {
  91. hr = pua->QueryEvent(pguidGrp, eCmd, wParam, lParam, pui);
  92. }
  93. return hr;
  94. }
  95. extern "C"
  96. HRESULT UEMSetEvent(const GUID *pguidGrp, int eCmd, WPARAM wParam, LPARAM lParam, LPUEMINFO pui)
  97. {
  98. HRESULT hr = E_FAIL;
  99. IUserAssist *pua;
  100. pua = GetUserAssist();
  101. if (pua) {
  102. hr = pua->SetEvent(pguidGrp, eCmd, wParam, lParam, pui);
  103. }
  104. return hr;
  105. }