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.

133 lines
2.8 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. ForceAnsiGetDisplayNameOf.cpp
  5. Abstract:
  6. This shim force the routine IShellFolder::GetDisplayNameOf to return
  7. an Ascii string whenever it detects that GetDisplayNameOf returned
  8. a unicode string.
  9. Notes:
  10. This is an app is generic.
  11. History:
  12. 07/26/2000 mnikkel Created
  13. --*/
  14. #include "precomp.h"
  15. IMPLEMENT_SHIM_BEGIN(ForceAnsiGetDisplayNameOf)
  16. #include "ShimHookMacro.h"
  17. APIHOOK_ENUM_BEGIN
  18. APIHOOK_ENUM_ENTRY(SHGetDesktopFolder)
  19. APIHOOK_ENUM_ENTRY_COMSERVER(SHELL32)
  20. APIHOOK_ENUM_END
  21. IMPLEMENT_COMSERVER_HOOK(SHELL32)
  22. /*++
  23. Hook SHGetDesktopFolder to get the IShellFolder Interface Pointer.
  24. --*/
  25. HRESULT
  26. APIHOOK(SHGetDesktopFolder)(
  27. IShellFolder **ppshf
  28. )
  29. {
  30. HRESULT hReturn;
  31. hReturn = ORIGINAL_API(SHGetDesktopFolder)(ppshf);
  32. if (SUCCEEDED(hReturn))
  33. {
  34. HookObject(
  35. NULL,
  36. IID_IShellFolder,
  37. (PVOID*)ppshf,
  38. NULL,
  39. FALSE);
  40. }
  41. return hReturn;
  42. }
  43. /*++
  44. Hook GetDisplayName of and when it returns a unicode string convert it over to
  45. an ANSI string.
  46. --*/
  47. HRESULT
  48. COMHOOK(IShellFolder, GetDisplayNameOf)(
  49. PVOID pThis,
  50. LPCITEMIDLIST pidl,
  51. DWORD uFlags,
  52. LPSTRRET lpName
  53. )
  54. {
  55. HRESULT hrReturn = E_FAIL;
  56. _pfn_IShellFolder_GetDisplayNameOf pfnOld =
  57. ORIGINAL_COM(IShellFolder, GetDisplayNameOf, pThis);
  58. if (pfnOld)
  59. {
  60. hrReturn = (*pfnOld)(pThis, pidl, uFlags, lpName);
  61. // Check for unicode string and validity
  62. if ((S_OK == hrReturn) && (lpName->uType == STRRET_WSTR) && lpName->pOleStr)
  63. {
  64. LPMALLOC pMalloc;
  65. LPWSTR pTemp;
  66. // Unicode found, convert it to ANSI and free the original unicode string.
  67. if (SUCCEEDED(SHGetMalloc(&pMalloc)))
  68. {
  69. // Save OleStr ptr. The OleStr ptr and the cStr are unioned together
  70. // so when we fill the cStr it will wipe out the OleStr ptr.
  71. pTemp = lpName->pOleStr;
  72. WideCharToMultiByte(CP_ACP, 0, pTemp, -1, lpName->cStr, MAX_PATH, NULL, NULL);
  73. // set the uType to CSTR and free the old unicode string.
  74. lpName->uType = STRRET_CSTR;
  75. pMalloc->Free(pTemp);
  76. LOGN(
  77. eDbgLevelError,
  78. "[IShellFolder_GetDisplayNameOf] Converted string from Unicode to ANSI: %s",
  79. lpName->cStr);
  80. }
  81. }
  82. }
  83. return hrReturn;
  84. }
  85. /*++
  86. Register hooked functions
  87. --*/
  88. HOOK_BEGIN
  89. APIHOOK_ENTRY_COMSERVER(SHELL32)
  90. APIHOOK_ENTRY(SHELL32.DLL, SHGetDesktopFolder)
  91. COMHOOK_ENTRY(ShellDesktop, IShellFolder, GetDisplayNameOf, 11)
  92. HOOK_END
  93. IMPLEMENT_SHIM_END