> I'm trying to write a CFX that will create a windows shortcut in
> a specific
> fold.  The location of the file is stored in a database and getting that
> information out is easy.  I can use CFFILE to copy yhe file over
> to the new
> folder, but that defeats what we want to do.
>
> Does any one know sone C++ code to create a windows shortcut?
> I've searched
> the MSDN library with no luck.

Sure. You'll need to fiddle with this (rather ancient code) depending on
WHERE you want the short cut, but it's 90% of the battle. At least it's
generic enough to be useful. :)

--min

//c++ IShellLink methods for accessing shortcuts
//based in part on the sparsely documented MS SDK code
BOOL CreateShortCut (const char *pszShortcutFile, const char *pszLinkPath,
const char *pszDesc, const char *pszWorkingDirectory, int iconid )
{
        HRESULT hres;
        IShellLink* psl;

        ::CoInitialize( NULL ); //warm up the COM libraries

        hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
IID_IShellLink, (void**)&psl);
        if (SUCCEEDED(hres))
        {
                IPersistFile* ppf;
                hres = psl->QueryInterface(IID_IPersistFile, (void**)&ppf);
                if (SUCCEEDED(hres))
                {
                        WCHAR wsz[MAX_PATH];
                        //set the path to the .exe file
                        hres = psl->SetPath(pszShortcutFile);
                        if (SUCCEEDED(hres))
                        {
                                //set the description (does this ever work?)
                                hres = psl->SetDescription(pszDesc);
                                if (SUCCEEDED(hres))
                                {
                                        //set the working directory
                                        hres = 
psl->SetWorkingDirectory(pszWorkingDirectory);
                                        if (SUCCEEDED(hres))
                                        {
                                                //use the first icon in the .exe file
                                                hres = 
psl->SetIconLocation(pszShortcutFile,iconid);
                                                if (SUCCEEDED(hres))
                                                {
                                                        //do it. commit the shortcut
                                                        ::MultiByteToWideChar(CP_ACP, 
0, pszLinkPath, -1, wsz, MAX_PATH);
                                                        hres = ppf->Save(wsz, TRUE);
                                                }
                                        }
                                }
                        }
                        ppf->Release();
                }
                psl->Release();
        }

        ::CoUninitialize(); //power down the COMs

        return SUCCEEDED(hres);
}

------------------------------------------------------------------------------
Archives: http://www.eGroups.com/list/cf-talk
To Unsubscribe visit 
http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk or send a 
message to [EMAIL PROTECTED] with 'unsubscribe' in the body.

Reply via email to