BCB Mailing List

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[BCB] Shortcut Files (*.lnk)



> I was hoping that someone can show me the way to create, read and modify
> shortcut files.

I've found an example somewhere in my archive. I haven't tried it yet, I hope it
works.

bool __fastcall TMainForm::CreateShortcut(void)
{
    HRESULT hres;
    IShellLink* psl;
    bool OK = false;

    /* Initialize COM. */
    CoInitialize(NULL);

    /* Get pointer to IShellLink interface. */
    hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
                            IID_IShellLink, (void * *)&psl);
    if(SUCCEEDED(hres)){
        IPersistFile* ppf;

        /* Set link details. */
        psl->SetPath(AnsiString(InstallDir+"MyProgram.exe").c_str());
        psl->SetDescription("My Program 1.0");

        hres = psl->QueryInterface(IID_IPersistFile, (void * *)&ppf);
        if(SUCCEEDED(hres)){
            AnsiString LinkPath =
                "C:\\Windows\\Start Menu\\Programs\\My Company\\MyProgram.lnk";
            OK = true;
            int Length = 50;
            wchar_t *wsz;
            wsz = LinkPath.WideChar(wsz,Length);
            ppf->Save(wsz, false);
            ppf->Release();
        }
        psl->Release();
    }

    CoUninitialize();

    return OK;
}

Tom





W Komornicki's Home Page | Main Index | Thread Index