Huw Davies (@huw) commented about dlls/shell32/shlview_cmenu.c:
if (counter == 1) {
wsprintfW(wszLinkFilename, L"%s - %s", wszFilename, shortcutW);
} else {
wsprintfW(wszLinkFilename, L"%s - %s (%u)", wszFilename, shortcutW, counter);
}
length = lstrlenW(root) + lstrlenW(wszLinkFilename) + lstrlenW(lnkW);
if (length > MAX_PATH) {
ERR("Path maximum length exceeded (%i>%i)\n", length, MAX_PATH);
IShellLinkW_Release(shelllink);
return;
}
PathCombineW(lnkfile, root, wszLinkFilename);
PathAddExtensionW(lnkfile, lnkW);
counter++;
- } while (PathFileExistsW(lnkfile));
This will be racey. However I wonder if shelllink's `IPersistFile_Save` should do this instead? A test would be good. If not, then I'd suggest actually trying to create the file in the loop.