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.

89 lines
2.3 KiB

  1. #include "stock.h"
  2. #pragma hdrstop
  3. #include <varutil.h>
  4. #include <shdocvw.h>
  5. // Use this file to house browser-related utility functions
  6. // -------------------------------------------------------------------
  7. // ANSI/UNICODE-neutral functions
  8. // these only need to be compiled once, so just do it UNICODE
  9. #ifdef UNICODE
  10. LPITEMIDLIST _ILCreateFromPathW(LPCWSTR pwszPath)
  11. {
  12. // use this shdocvw export, this deals with down level shells and funky url parsing
  13. LPITEMIDLIST pidl;
  14. return SUCCEEDED(IEParseDisplayNameWithBCW(CP_ACP, pwszPath, NULL, &pidl)) ? pidl : NULL;
  15. }
  16. STDAPI_(LPITEMIDLIST) VariantToIDList(const VARIANT *pv)
  17. {
  18. LPITEMIDLIST pidl = NULL;
  19. if (pv)
  20. {
  21. if (pv->vt == (VT_BYREF | VT_VARIANT) && pv->pvarVal)
  22. pv = pv->pvarVal;
  23. switch (pv->vt)
  24. {
  25. case VT_I2:
  26. pidl = SHCloneSpecialIDList(NULL, pv->iVal, TRUE);
  27. break;
  28. case VT_I4:
  29. case VT_UI4:
  30. if (pv->lVal < 0xFFFF)
  31. {
  32. pidl = SHCloneSpecialIDList(NULL, pv->lVal, TRUE);
  33. }
  34. #ifndef _WIN64
  35. //We make sure we use it as a pointer only in Win32
  36. else
  37. {
  38. pidl = ILClone((LPCITEMIDLIST)pv->byref); // HACK in process case, avoid the use of this if possible
  39. }
  40. #endif // _WIN64
  41. break;
  42. //In Win64, the pidl variant could be 8 bytes long!
  43. case VT_I8:
  44. case VT_UI8:
  45. if(pv->ullVal < 0xFFFF)
  46. {
  47. pidl = SHCloneSpecialIDList(NULL, (int)pv->ullVal, TRUE);
  48. }
  49. #ifdef _WIN64
  50. //We make sure we use it as a pointer only in Win64
  51. else
  52. {
  53. pidl = ILClone((LPCITEMIDLIST)pv->ullVal); // HACK in process case, avoid the use of this if possible
  54. }
  55. #endif //_WIN64
  56. break;
  57. case VT_BSTR:
  58. pidl = _ILCreateFromPathW(pv->bstrVal);
  59. break;
  60. case VT_ARRAY | VT_UI1:
  61. pidl = ILClone((LPCITEMIDLIST)pv->parray->pvData);
  62. break;
  63. case VT_DISPATCH | VT_BYREF:
  64. if (pv->ppdispVal)
  65. SHGetIDListFromUnk(*pv->ppdispVal, &pidl);
  66. break;
  67. case VT_DISPATCH:
  68. SHGetIDListFromUnk(pv->pdispVal, &pidl);
  69. break;
  70. }
  71. }
  72. return pidl;
  73. }
  74. #endif // UNICODE