Back to index

lightning-sunbird  0.9+nobinonly
Defines | Functions
nsWinShortcut.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define MAX_BUF   4096

Functions

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

Define Documentation

#define MAX_BUF   4096

Definition at line 44 of file nsWinShortcut.h.


Function Documentation

long 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: