示例#1
0
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;
}
示例#2
0
文件: shell.c 项目: UIKit0/wine-1
static HRESULT WINAPI WshShortcut_put_Description(IWshShortcut *iface, BSTR Description)
{
    WshShortcut *This = impl_from_IWshShortcut(iface);
    TRACE("(%p)->(%s)\n", This, debugstr_w(Description));
    return IShellLinkW_SetDescription(This->link, Description);
}