50 lines
1.6 KiB
C++
Raw Normal View History

2024-11-05 15:46:45 +08:00
DECLARE_API void GetLnkTargetPath(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-01-08 23:37:00 +08:00
CoInitialize(NULL);
2024-12-29 15:35:27 +08:00
CComPtr<IShellLink> shellLink;
2024-04-02 15:36:52 +08:00
HRESULT hr = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID *)&shellLink);
2024-01-08 23:37:00 +08:00
2024-04-02 15:36:52 +08:00
if (SUCCEEDED(hr))
{
2024-12-29 15:35:27 +08:00
CComPtr<IPersistFile> persistFile;
auto hr = shellLink.QueryInterface(&persistFile);
2024-04-02 15:36:52 +08:00
if (SUCCEEDED(hr))
{
2024-01-08 23:37:00 +08:00
WCHAR wsz[MAX_PATH];
StringCchCopy(wsz, MAX_PATH, lnkFilePath);
hr = persistFile->Load(wsz, STGM_READ);
2024-04-02 15:36:52 +08:00
if (SUCCEEDED(hr))
{
2024-01-08 23:37:00 +08:00
hr = shellLink->Resolve(NULL, SLR_NO_UI);
2024-04-02 15:36:52 +08:00
if (SUCCEEDED(hr))
{
2024-01-08 23:37:00 +08:00
WIN32_FIND_DATA findData;
int x;
2024-04-02 15:36:52 +08:00
hr = shellLink->GetIconLocation(iconpath, MAX_PATH, &x);
if (FAILED(hr))
wcscpy(iconpath, L"");
hr = shellLink->GetArguments(tgtpath, MAX_PATH);
if (FAILED(hr))
wcscpy(tgtpath, L"");
2024-01-08 23:37:00 +08:00
hr = shellLink->GetPath(path, MAX_PATH, &findData, SLGP_RAWPATH);
if (FAILED(hr))
2024-04-02 15:36:52 +08:00
wcscpy(path, L"");
hr = shellLink->GetWorkingDirectory(dirpath, MAX_PATH);
2024-01-08 23:37:00 +08:00
if (FAILED(hr))
2024-04-02 15:36:52 +08:00
wcscpy(path, L"");
2024-01-08 23:37:00 +08:00
}
}
}
}
CoUninitialize();
}