SHELL.CPP 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /** (c) Nullsoft, Inc. C O N F I D E N T I A L
  2. ** Filename:
  3. ** Project:
  4. ** Description:
  5. ** Author:
  6. ** Created:
  7. **/
  8. #include "main.h"
  9. #include "../nu/ns_wc.h"
  10. extern "C"
  11. {
  12. HRESULT ResolveShortCut(HWND hwnd, LPCWSTR pszShortcutFile, LPWSTR pszPath)
  13. {
  14. IShellLinkW *psl = 0;
  15. WIN32_FIND_DATAW wfd = {0};
  16. *pszPath = 0; // assume failure
  17. HRESULT hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLinkW, (void **) & psl);
  18. if (SUCCEEDED(hres))
  19. {
  20. IPersistFile *ppf = 0;
  21. hres = psl->QueryInterface(IID_IPersistFile, (void **) &ppf); // OLE 2! Yay! --YO
  22. if (SUCCEEDED(hres))
  23. {
  24. hres = ppf->Load(pszShortcutFile, STGM_READ);
  25. if (SUCCEEDED(hres))
  26. {
  27. hres = psl->Resolve(hwnd, SLR_ANY_MATCH);
  28. if (SUCCEEDED(hres))
  29. {
  30. wchar_t szGotPath[MAX_PATH] = {0};
  31. StringCchCopyW(szGotPath, MAX_PATH, pszShortcutFile);
  32. hres = psl->GetPath(szGotPath, MAX_PATH, & wfd,
  33. SLGP_SHORTPATH );
  34. StringCchCopyW(pszPath, MAX_PATH, szGotPath);
  35. }
  36. }
  37. ppf->Release();
  38. }
  39. psl->Release();
  40. }
  41. return SUCCEEDED(hres);
  42. }
  43. /*void CreateShortCut(HWND hwnd, LPCSTR pszShortcutFile, LPCSTR pszExe, LPCSTR pszArg, int iconindex)
  44. {
  45. HRESULT hres;
  46. IShellLink* psl;
  47. hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
  48. IID_IShellLink, (void **) & psl);
  49. if (SUCCEEDED(hres))
  50. {
  51. IPersistFile* ppf;
  52. hres = psl->QueryInterface(IID_IPersistFile, (void **) & ppf); // OLE 2! Yay! --YO
  53. if (SUCCEEDED(hres))
  54. {
  55. wchar_t wsz[MAX_PATH] = {0};
  56. MultiByteToWideCharSZ(CP_ACP, 0, pszShortcutFile, -1, wsz, MAX_PATH);
  57. hres = psl->SetPath(pszExe);
  58. if (pszArg)
  59. {
  60. psl->SetArguments(pszArg);
  61. }
  62. psl->SetIconLocation(pszExe, iconindex);
  63. if (SUCCEEDED(hres))
  64. {
  65. ppf->Save(wsz, TRUE);
  66. }
  67. ppf->Release();
  68. }
  69. psl->Release();
  70. }
  71. }*/
  72. void Shell_Free(void *p)
  73. {
  74. CoTaskMemFree(p);
  75. }
  76. }