+ //Check to see if it's already a link.
+ if (!wcsicmp(pwszExt, L".lnk"))
+ {
+ //It's a link so, we create a new one which copies the old.
+ if(!GetUniqueFileName(placementPath, pwszExt, wszTarget, TRUE))
+ {
+ ERR("Error getting unique file name");
+ hr = E_FAIL;
+ break;
+ }
+ hr = IShellLink_ConstructFromFile(NULL, IID_IPersistFile, ILCombine(pidl, apidl[i]), (LPVOID*)&ppf);
+ if (FAILED(hr)) {
+ ERR("Error constructing link from file");
+ break;
+ }
+
+ hr = ppf->Save(wszTarget, FALSE);
+ }
+ else
+ {
+ //It's not a link, so build a new link using the creator class and fill it in.
+ //Create a file name for the link
+ if (!GetUniqueFileName(placementPath, L".lnk", wszTarget, TRUE))
+ {
+ ERR("Error creating unique file name");
+ hr = E_FAIL;
+ break;
+ }
+
+ CComPtr<IShellLinkW> pLink;
+ hr = CShellLink::_CreatorClass::CreateInstance(NULL, IID_PPV_ARG(IShellLinkW, &pLink));
+ if (FAILED(hr)) {
+ ERR("Error instantiating IShellLinkW");
+ break;
+ }
+
+ WCHAR szDirPath[MAX_PATH], *pwszFile;
+ GetFullPathName(wszPath, MAX_PATH, szDirPath, &pwszFile);
+ if (pwszFile) pwszFile[0] = 0;
+
+ hr = pLink->SetPath(wszPath);
+ if(FAILED(hr))
+ break;
+
+ hr = pLink->SetWorkingDirectory(szDirPath);
+ if(FAILED(hr))
+ break;
+
+ hr = pLink->QueryInterface(IID_PPV_ARG(IPersistFile, &ppf));
+ if(FAILED(hr))
+ break;
+
+ hr = ppf->Save(wszTarget, TRUE);
+ }
+ }
+ }
+ else
+ {
+ hr = this->CopyItems(psfFrom, lpcida->cidl, (LPCITEMIDLIST*)apidl, bCopy);
+ }