1
我試圖創建快捷方式以編程文件夾,因爲它是通過在文件夾 - 右鍵單擊>創建快捷方式在Windows上創建文件夾快捷方式程序
我用做
IShellLink* pShellLink;
IPersistFile* pPersistFile;
//........
hRes = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink,
(LPVOID*)&pShellLink);
//.....
hRes = pShellLink->SetPath(pszTargetfile);
hRes = pShellLink->SetArguments(pszTargetargs);
if (wcslen(pszDescription) > 0)
{
hRes = pShellLink->SetDescription(pszDescription);
}
if (wcslen(pszCurdir) > 0)
{
hRes = pShellLink->SetWorkingDirectory(pszCurdir);
}
if (wcslen(pszIconfile) > 0 && iIconindex >= 0)
{
hRes = pShellLink->SetIconLocation(pszIconfile, iIconindex);
}
hRes = pShellLink->QueryInterface(IID_IPersistFile, (LPVOID*)&pPersistFile);
if (SUCCEEDED(hRes))
{
wcscpy_s(wszLinkfile, pszLinkfile);
hRes = pPersistFile->Save(wszLinkfile, TRUE);
pPersistFile->Release();
}
pShellLink->Release();
//....
之後,我得到XXX.lnk文件。然後我雙擊它並看到「Open With」窗口而不是重定向到destinaiton文件夾。 我的目標類型設置爲「文件」,而不是「文件夾」(如手動創建一個快捷方式的情況下)我LNK屬性中找到
它應該工作作爲符號鏈接,但我需要的是一個快捷方式(所以我不用CreateSymbolicLink)
如何正確地做到這一點?
你似乎並沒有被設置鏈接的目標 - 你需要調用'::的IShellLink或SetPath''::的IShellLink SetIDList' 。 –
@Jonathan Potter我使用SetPath(我更新了代碼),但是如何使用SetIDList? – amplifier