C++如何取到桌面其中一个快捷方式图标里的起始位置
比如说安装了个360杀毒软件,并在桌面上创建了360杀毒软件的快捷方式。它的属性里有个“起始位置”,如"C:\Program Files\360\360sd"。 我要写一个C++程序,只知道360杀毒软件快捷图标的名称,要取到“起始位置”的字符串"C:\Program Files\360\360sd"。 如何写?桌面路径取当前用户的桌面路径。也就是说:如果一台机子上开了好几个用户账号,那就取登陆的那个的桌面地址。假设每一个用户都安装了360杀毒,并生成桌面图标.
[解决办法]
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();
}
CoInitialize(0);
CShellLink obj;
obj.Load(_T("C:/Documents and Settings/bizuser/桌面/金山词霸2007.lnk"));
CString str = obj.GetPath();
AfxMessageBox(str);
CoUninitialize();