Back to index

lightning-sunbird  0.9+nobinonly
Functions
nsWinShortcut.cpp File Reference
#include <shlobj.h>
#include <shlguid.h>
#include "nsWinShortcut.h"

Go to the source code of this file.

Functions

HRESULT CreateALink (LPCSTR lpszPathObj, LPCSTR lpszPathLink, LPCSTR lpszDesc, LPCSTR lpszWorkingPath, LPCSTR lpszArgs, LPCSTR lpszIconFullPath, int iIcon)

Function Documentation

HRESULT CreateALink ( LPCSTR  lpszPathObj,
LPCSTR  lpszPathLink,
LPCSTR  lpszDesc,
LPCSTR  lpszWorkingPath,
LPCSTR  lpszArgs,
LPCSTR  lpszIconFullPath,
int  iIcon 
)

Definition at line 54 of file nsWinShortcut.cpp.

{ 
    HRESULT    hres; 
    IShellLink *psl;
    char       lpszFullPath[MAX_BUF];

    lstrcpy(lpszFullPath, lpszPathLink);
    lstrcat(lpszFullPath, "\\");
    lstrcat(lpszFullPath, lpszDesc);
    lstrcat(lpszFullPath, ".lnk");

    CreateDirectory(lpszPathLink, NULL);
    CoInitialize(NULL);

    // Get a pointer to the IShellLink interface. 
    hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID *)&psl); 
    if(SUCCEEDED(hres))
    { 
        IPersistFile* ppf; 
 
        // Set the path to the shortcut target, and add the 
        // description. 
        psl->SetPath(lpszPathObj);

        // Do not set the description at this time.  We need to fix this
        // parameter so it can be passed in independent of the shortcut name
        // itself.  Comment this code out for now until a real fix can be done.
        // psl->SetDescription(lpszDesc);

        if(lpszWorkingPath)
            psl->SetWorkingDirectory(lpszWorkingPath);
        if(lpszArgs)
            psl->SetArguments(lpszArgs);
        psl->SetIconLocation(lpszIconFullPath, iIcon);
 
        // Query IShellLink for the IPersistFile interface for saving the 
        // shortcut in persistent storage. 
        hres = psl->QueryInterface(IID_IPersistFile, (LPVOID FAR *)&ppf); 
        if(SUCCEEDED(hres))
        { 
            WORD wsz[MAX_BUF]; 
 
            // Ensure that the string is ANSI. 
            MultiByteToWideChar(CP_ACP, 0, lpszFullPath, -1, (wchar_t *)wsz, MAX_BUF);
 
            // Save the link by calling IPersistFile::Save. 
            hres = ppf->Save((wchar_t *)wsz, TRUE); 
            ppf->Release(); 
        } 
        psl->Release(); 
    } 
    CoUninitialize();

    return hres;
}

Here is the call graph for this function: