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.

143 lines
3.6 KiB

  1. /*
  2. * shlexhk.cpp - IShellExecuteHook implementation for URL class.
  3. */
  4. /* Headers
  5. **********/
  6. #include "project.hpp"
  7. #pragma hdrstop
  8. /* Module Constants
  9. *******************/
  10. #pragma data_seg(DATA_SEG_READ_ONLY)
  11. PRIVATE_DATA const char s_cszOpenVerb[] = "open";
  12. #pragma data_seg()
  13. /********************************** Methods **********************************/
  14. HRESULT STDMETHODCALLTYPE InternetShortcut::Execute(PSHELLEXECUTEINFO pei)
  15. {
  16. HRESULT hr;
  17. DebugEntry(InternetShortcut::Execute);
  18. ASSERT(IS_VALID_STRUCT_PTR(this, CInternetShortcut));
  19. ASSERT(IS_VALID_STRUCT_PTR(pei, CSHELLEXECUTEINFO));
  20. if (! pei->lpVerb ||
  21. ! lstrcmpi(pei->lpVerb, s_cszOpenVerb))
  22. {
  23. if (pei->lpFile)
  24. {
  25. PSTR pszTranslatedURL;
  26. hr = TranslateURL(pei->lpFile, TRANSLATEURL_FL_GUESS_PROTOCOL,
  27. &pszTranslatedURL);
  28. if (SUCCEEDED(hr))
  29. {
  30. PCSTR pcszURLToUse;
  31. pcszURLToUse = (hr == S_OK) ? pszTranslatedURL : pei->lpFile;
  32. hr = ValidateURL(pcszURLToUse);
  33. if (hr == S_OK)
  34. {
  35. hr = SetURL(pcszURLToUse, 0);
  36. if (hr == S_OK)
  37. {
  38. URLINVOKECOMMANDINFO urlici;
  39. EVAL(SetShowCmd(pei->nShow) == S_OK);
  40. urlici.dwcbSize = sizeof(urlici);
  41. urlici.hwndParent = pei->hwnd;
  42. urlici.pcszVerb = NULL;
  43. urlici.dwFlags = IURL_INVOKECOMMAND_FL_USE_DEFAULT_VERB;
  44. if (IS_FLAG_CLEAR(pei->fMask, SEE_MASK_FLAG_NO_UI))
  45. SET_FLAG(urlici.dwFlags, IURL_INVOKECOMMAND_FL_ALLOW_UI);
  46. hr = InvokeCommand(&urlici);
  47. if (hr != S_OK)
  48. {
  49. SET_FLAG(pei->fMask, SEE_MASK_FLAG_NO_UI);
  50. TRACE_OUT(("InternetShortcut::Execute(): InternetShortcut::InvokeCommand() failed, returning %s. Clearing SEE_MASK_FLAG_NO_UI to avoid error ui from ShellExecute().",
  51. GetHRESULTString(hr)));
  52. }
  53. }
  54. }
  55. if (pszTranslatedURL)
  56. {
  57. LocalFree(pszTranslatedURL);
  58. pszTranslatedURL = NULL;
  59. }
  60. }
  61. }
  62. else
  63. // This hook only handles execution of file string, not IDList.
  64. hr = S_FALSE;
  65. }
  66. else
  67. // Unrecognized verb.
  68. hr = S_FALSE;
  69. if (hr == S_OK)
  70. pei->hInstApp = (HINSTANCE)42;
  71. else if (FAILED(hr))
  72. {
  73. switch (hr)
  74. {
  75. case URL_E_INVALID_SYNTAX:
  76. case URL_E_UNREGISTERED_PROTOCOL:
  77. hr = S_FALSE;
  78. break;
  79. case E_OUTOFMEMORY:
  80. pei->hInstApp = (HINSTANCE)SE_ERR_OOM;
  81. hr = E_FAIL;
  82. break;
  83. case IS_E_EXEC_FAILED:
  84. // Translate execution failure into "file not found".
  85. pei->hInstApp = (HINSTANCE)SE_ERR_FNF;
  86. hr = E_FAIL;
  87. break;
  88. default:
  89. // pei->lpFile is bogus. Treat as file not found.
  90. ASSERT(hr == E_POINTER);
  91. // We should never get E_FLAGS from TranslateURL() here.
  92. pei->hInstApp = (HINSTANCE)SE_ERR_FNF;
  93. hr = E_FAIL;
  94. break;
  95. }
  96. }
  97. else
  98. ASSERT(hr == S_FALSE);
  99. ASSERT(IS_VALID_STRUCT_PTR(this, CInternetShortcut));
  100. ASSERT(IS_VALID_STRUCT_PTR(pei, CSHELLEXECUTEINFO));
  101. ASSERT(hr == S_OK ||
  102. hr == S_FALSE ||
  103. hr == E_FAIL);
  104. DebugExitHRESULT(InternetShortcut::Execute, hr);
  105. return(hr);
  106. }