62 lines
1.8 KiB
C++
Raw Normal View History

2024-04-02 15:36:52 +08:00
#include <Shobjidl.h>
2024-01-08 23:37:00 +08:00
#include <Windows.h>
#include <Shobjidl.h>
#include <iostream>
#include <initguid.h>
#include <ShlGuid.h>
#include <strsafe.h>
2024-04-02 15:36:52 +08:00
#include "define.h"
void GetLnkTargetPath(wchar_t *lnkFilePath, wchar_t *path, wchar_t *tgtpath, wchar_t *iconpath, wchar_t *dirpath)
{
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();
}