static HRESULT WINAPI WshShortcut_put_IconLocation(IWshShortcut *iface, BSTR IconPath) { WshShortcut *This = impl_from_IWshShortcut(iface); HRESULT hr; WCHAR *ptr; BSTR path; INT icon; TRACE("(%p)->(%s)\n", This, debugstr_w(IconPath)); /* scan for icon id */ ptr = strrchrW(IconPath, ','); if (!ptr) { WARN("icon index not found\n"); return E_FAIL; } path = SysAllocStringLen(IconPath, ptr-IconPath); /* skip spaces if any */ while (isspaceW(*++ptr)) ; icon = atoiW(ptr); hr = IShellLinkW_SetIconLocation(This->link, path, icon); SysFreeString(path); return hr; }
VOID SetupCreateLink( _In_ PWSTR LinkFilePath, _In_ PWSTR FilePath, _In_ PWSTR FileParentDir ) { IShellLink* shellLinkPtr = NULL; IPersistFile* persistFilePtr = NULL; if (FAILED(CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, &IID_IShellLink, &shellLinkPtr))) goto CleanupExit; if (FAILED(IShellLinkW_QueryInterface(shellLinkPtr, &IID_IPersistFile, &persistFilePtr))) goto CleanupExit; // Load existing shell item if it exists... //IPersistFile_Load(persistFilePtr, LinkFilePath, STGM_READ) //IShellLinkW_SetDescription(shellLinkPtr, FileComment); IShellLinkW_SetWorkingDirectory(shellLinkPtr, FileParentDir); IShellLinkW_SetIconLocation(shellLinkPtr, FilePath, 0); // Set the shortcut target path... if (FAILED(IShellLinkW_SetPath(shellLinkPtr, FilePath))) goto CleanupExit; // Save the shortcut to the file system... IPersistFile_Save(persistFilePtr, LinkFilePath, TRUE); CleanupExit: if (persistFilePtr) IPersistFile_Release(persistFilePtr); if (shellLinkPtr) IShellLinkW_Release(shellLinkPtr); }
BOOLEAN CreateLink( _In_ PWSTR DestFilePath, _In_ PWSTR FilePath, _In_ PWSTR FileParentDir, _In_ PWSTR FileComment ) { IShellLink* shellLinkPtr = NULL; IPersistFile* persistFilePtr = NULL; BOOLEAN isSuccess = FALSE; __try { if (FAILED(CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, &IID_IShellLink, &shellLinkPtr))) __leave; if (FAILED(IShellLinkW_QueryInterface(shellLinkPtr, &IID_IPersistFile, &persistFilePtr))) __leave; // Load existing shell item if it exists... //if (SUCCEEDED(IPersistFile_Load(persistFilePtr, DestFilePath, STGM_READ))) //{ // IShellLinkW_Resolve(shellLinkPtr, NULL, 0); //} IShellLinkW_SetDescription(shellLinkPtr, FileComment); IShellLinkW_SetWorkingDirectory(shellLinkPtr, FileParentDir); IShellLinkW_SetIconLocation(shellLinkPtr, FilePath, 0); // Set the shortcut target path... if (FAILED(IShellLinkW_SetPath(shellLinkPtr, FilePath))) __leave; // Save the shortcut to the file system... if (FAILED(IPersistFile_Save(persistFilePtr, DestFilePath, TRUE))) __leave; isSuccess = TRUE; } __finally { if (persistFilePtr) { IPersistFile_Release(persistFilePtr); } if (shellLinkPtr) { IShellLinkW_Release(shellLinkPtr); } } return isSuccess; }