64,666
社区成员
发帖
与我相关
我的任务
分享
void QdSetup::GetLinkPath(wchar_t *lpszLink, wchar_t *szPath, wchar_t *szParam)
{
HRESULT hres;
IShellLink* psl;
wchar_t szGotPath[MAX_PATH];
wchar_t szArguement[MAX_PATH];
WIN32_FIND_DATA wfd;
*szPath = 0; // assume failure
CoInitialize(0);
// Get a pointer to the IShellLink interface.
hres = CoCreateInstance(CLSID_ShellLink, NULL,
CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID *) &psl);
if (SUCCEEDED(hres)) {
IPersistFile* ppf;
// Get a pointer to the IPersistFile interface.
hres = psl->QueryInterface(IID_IPersistFile,
(void**)&ppf);
if (SUCCEEDED(hres)) {
//WCHAR wsz[MAX_PATH];
//// Ensure that the string is Unicode.
//MultiByteToWideChar(CP_ACP, 0, lpszLink, -1, wsz,
// MAX_PATH);
// Load the shortcut.
hres = ppf->Load(lpszLink, STGM_READ);
if (SUCCEEDED(hres)) {
// Resolve the link.
hres = psl->Resolve(0, 0);
if (SUCCEEDED(hres)) {
// Get the path to the link target.
hres = psl->GetPath(szGotPath,
MAX_PATH, (WIN32_FIND_DATA *)&wfd,
SLGP_SHORTPATH );
if (SUCCEEDED(hres))
lstrcpy(szPath, szGotPath);
hres = psl->GetArguments(szArguement, 256);
if(SUCCEEDED(hres))
lstrcpy(szParam, szArguement);
}
}
// Release the pointer to the IPersistFile interface.
ppf->Release();
}
// Release the pointer to the IShellLink interface.
psl->Release();
}
if(hres)
lstrcpy(szPath, lpszLink);
CoUninitialize();
}
LPITEMIDLIST pidl;
HRESULT hr= SHGetSpecialFolderLocation(NULL, CSIDL_DESKTOP, &pidl);
TCHAR szPath[MAX_PATH];
SHGetPathFromIDList(pidl, szPath);
CString strQPath =szPath; //桌面路径
CoInitialize(0);
CShellLink cshelllink;
if(cshelllink.Load(_T("C:\Documents and Settings\liu\桌面\360杀毒.lnk")))
{
CString strtemp = cshelllink.GetPath();
}
CoInitialize(0);
CShellLink obj;
obj.Load(_T("C:/Documents and Settings/bizuser/桌面/金山词霸2007.lnk"));
CString str = obj.GetPath();
AfxMessageBox(str);
CoUninitialize();