55 lines
1.7 KiB
C++
Raw Permalink 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-04-02 15:36:52 +08:00
IShellLink *shellLink;
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))
{
IPersistFile *persistFile;
hr = shellLink->QueryInterface(IID_IPersistFile, (LPVOID *)&persistFile);
2024-01-08 23:37:00 +08:00
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
}
}
persistFile->Release();
}
shellLink->Release();
}
CoUninitialize();
}