1

I'm trying to create shortcut to folder programmatically as it would be by right-clicking on a folder->create short cut

I'm doing it using

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();
//....

After that I get XXX.lnk file. Then I double click it and see the window "Open With" instead of redirecting to the destinaiton folder. I found in my lnk properties that the target type is set to 'File' instead of 'File folder' (as in the case of creating a shortcut manually)

It should work as symlink but I need it to be a shortcut (so I don't use CreateSymbolicLink)

How to do it properly?

2
  • 1
    You don't appear to be setting the link's target - you need to call either IShellLink::SetPath or IShellLink::SetIDList. Commented Oct 29, 2013 at 7:56
  • @Jonathan Potter I use SetPath (I've updated the code), but how to use SetIDList? Commented Oct 29, 2013 at 9:16

1 Answer 1

1

I figured out - the slashes in the destination path must be backward

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.