28 lines
1019 B
C++
Raw Normal View History

2024-11-05 15:46:45 +08:00
2024-12-29 18:09:35 +08:00
DECLARE_API void GetLnkTargetPath(const wchar_t *lnkFilePath, wchar_t *path, wchar_t *tgtpath, wchar_t *iconpath, wchar_t *dirpath)
2024-04-02 15:36:52 +08:00
{
wcscpy(path, L"");
wcscpy(tgtpath, L"");
wcscpy(iconpath, L"");
2024-12-29 18:09:35 +08:00
wcscpy(dirpath, L"");
CO_INIT co;
CHECK_FAILURE_NORET(co);
2024-12-29 15:35:27 +08:00
CComPtr<IShellLink> shellLink;
2024-12-29 18:09:35 +08:00
CHECK_FAILURE_NORET(CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID *)&shellLink));
2024-01-08 23:37:00 +08:00
2024-12-29 18:09:35 +08:00
CComPtr<IPersistFile> persistFile;
CHECK_FAILURE_NORET(shellLink.QueryInterface(&persistFile));
WCHAR wsz[MAX_PATH];
StringCchCopy(wsz, MAX_PATH, lnkFilePath);
2024-01-08 23:37:00 +08:00
2024-12-29 18:09:35 +08:00
CHECK_FAILURE_NORET(persistFile->Load(lnkFilePath, STGM_READ));
2024-01-08 23:37:00 +08:00
2024-12-29 18:09:35 +08:00
CHECK_FAILURE_NORET(shellLink->Resolve(NULL, SLR_NO_UI));
2024-01-08 23:37:00 +08:00
2024-12-29 18:09:35 +08:00
WIN32_FIND_DATA findData;
int x;
shellLink->GetIconLocation(iconpath, MAX_PATH, &x);
shellLink->GetArguments(tgtpath, MAX_PATH);
shellLink->GetPath(path, MAX_PATH, &findData, SLGP_RAWPATH);
shellLink->GetWorkingDirectory(dirpath, MAX_PATH);
2024-01-08 23:37:00 +08:00
}