Solved

When is a shortcut not a shortcut ???

Posted on 1998-10-15
5
284 Views
Last Modified: 2013-11-20
On the desktop there are 'shortcut like' objects such as the InBox and 'Internet Explorer'. The shortcuts are generated through IShellLink. As far as I can tell these other objects are generated through IShellFolder.
Is this correct, and more importantly how can I set one up to reference my executable ??
Points will only be awarded for a complete answer.
0
Comment
Question by:Bridge
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 6

Expert Comment

by:snoegler
ID: 1323334
(Parts of the code below are taken from a KB article, but i don't know its ID anymore)

// CreateLink - uses the shell's IShellLink and IPersistFile interfaces
//   to create and store a shortcut to the specified object.
// Returns the result of calling the member functions of the interfaces.
// lpszPathObj - address of a buffer containing the path of the object
// lpszPathLink - address of a buffer containing the path where the
//   shell link is to be stored
// lpszDesc - address of a buffer containing the description of the
//   shell link
 
HRESULT CreateLink(LPCSTR lpszPathObj,
    LPCSTR lpszPathLink, LPCSTR lpszDesc)
{
    HRESULT hres;
    IShellLink* psl;
 
    // Get a pointer to the IShellLink interface.
    hres = ::CoCreateInstance(CLSID_ShellLink, NULL,
        CLSCTX_INPROC_SERVER, IID_IShellLink, (void **)&psl);
    if (SUCCEEDED(hres)) {
        ::IPersistFile* ppf;
 
        // Set the path to the shortcut target, and add the
        // description.
        psl->SetPath(lpszPathObj);
        psl->SetDescription(lpszDesc);
 
       // Query IShellLink for the IPersistFile interface for saving the
       // shortcut in persistent storage.
        hres = psl->QueryInterface(IID_IPersistFile,
            (void **)&ppf);
 
        if (SUCCEEDED(hres)) {
            WORD wsz[MAX_PATH];
 
            // Ensure that the string is ANSI.
            ::MultiByteToWideChar(CP_ACP, 0, lpszPathLink, -1,
                wsz, MAX_PATH);
 
            // Save the link by calling IPersistFile::Save.
            hres = ppf->Save(wsz, TRUE);
            ppf->Release();
        }
            psl->Resolve(NULL,SLR_NO_UI|SLR_UPDATE);
        psl->Release();
    }
    return hres;
}
 
BOOL MakeLink(int csidlFolder,LPCTSTR lpszRelPathToLink, LPCTSTR lpszDescription, LPCTSTR lpszLinkTo)
{
    LPITEMIDLIST    pidl;
    TCHAR           buffer[MAX_PATH];
    CString         sFullPath;

    if(SHGetSpecialFolderLocation(NULL,csidlFolder,&pidl)!=NOERROR)
          return FALSE;
    if(!SHGetPathFromIDList(pidl,buffer))
          return FALSE;

    sFullPath       =buffer;
    sFullPath       +=lpszRelPathToLink;

    // Check if there are subdirectories to create
    CString         sTemp;
    int                        iStart=0;
    int             iSlashPos;

    sTemp           =sFullPath;
    do  {
        sTemp       =sFullPath.Mid(iStart);
        iSlashPos   =sTemp.Find('\\');

        if(iSlashPos!=-1) {
            sTemp   =sFullPath.Mid(0,iStart+iSlashPos);
            iStart  =iStart+iSlashPos+1;
        }   else
            sTemp   =sFullPath;
       
        CreateDirectory(sTemp,NULL);
    }   while(iSlashPos!=-1);

    sFullPath+="\\";
    sFullPath+=lpszDescription;

    if(CreateLink(lpszLinkTo,sFullPath,lpszDescription)!=NOERROR)
        return FALSE;

    return TRUE;
}

This is a part of a working application (with a little changes).
To use it, you need to call MakeLink() like this:

MakeLink(CSIDL_DESKTOP,"\\My Application Group",
                  "My Application","C:\\MYAPP\\MYAPP.EXE");

or

MakeLink(CSIDL_PROGRAMS,"\\My Application Group",
                  "My Application","C.\\MYAPP\\MYAPP.EXE");

You have to include winnls.h, winnetwk.h, and shlobj.h. Also, you must call CoInitialize() in
your InitInstance() handler.
Hope this helps,

snoegler

P.S: Lots of information on shell links and so on can be found at www.codeguru.com
0
 
LVL 1

Author Comment

by:Bridge
ID: 1323335
From looking at your answer it seem to generate a shortcut. I know how to do this already.
Maybe I wansnt clear enough in the question.
If you look at the desktop through Explorer you will see some 'system folder' objects. I want to know how these are generated, I think it is through IShellFolder.
Any ideas.
0
 
LVL 32

Accepted Solution

by:
jhance earned 200 total points
ID: 1323336
The "links" on the desktop that look like shortcuts but aren't are created using their CLSIDs.  for example, use REGEDIT and look at:

HKEY_CLASSES_ROOT\CLSID\{645FF040-5081-101B-9F08-00AA002F954E}

This is the CLSID for the Recycle Bin.  This is added to the desktop folder with:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace\{645FF040-5081-101B-9F08-00AA002F954E}


0
 
LVL 32

Expert Comment

by:jhance
ID: 1323337
BTW, the process for creating "Namespace Extensions" is not terribly difficult but it is somewhat complicated.  Most advanced Windows programming books have explanations of how to build namespace extension DLLs and add them to the Desktop.
0
 
LVL 1

Author Comment

by:Bridge
ID: 1323338
You forgot that you must put at least
shell
  open
    command

in for it to be of any use though. You can have the points anyway.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
while loop over for loop 7 119
either24  challenge 19 110
modThree challenge 4 155
Message not shown 5 104
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question