Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. desktop shortcut

desktop shortcut

Scheduled Pinned Locked Moved C / C++ / MFC
linux
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mr_Byte
    wrote on last edited by
    #1

    I need to create a shortcut on the desktop by my program note: I Know nothing about shell programming:confused: thanks in advance MR.Byte

    D 1 Reply Last reply
    0
    • M Mr_Byte

      I need to create a shortcut on the desktop by my program note: I Know nothing about shell programming:confused: thanks in advance MR.Byte

      D Offline
      D Offline
      Deepak Khajuria
      wrote on last edited by
      #2

      The following code should do:

      HRESULT CreateShortcut(LPCSTR pszShortcutFile, LPSTR pszLink,
      LPSTR pszDesc)
      {
      HRESULT hres;
      IShellLink* psl;

      // Get a pointer to the IShellLink interface.
      hres = CoCreateInstance(CLSID\_ShellLink, NULL, CLSCTX\_INPROC\_SERVER,
                              IID\_IShellLink, &psl);
      if (SUCCEEDED(hres))
      {
         IPersistFile\* ppf;
      
         // Query IShellLink for the IPersistFile interface for 
         // saving the shell link in persistent storage.
         hres = psl->QueryInterface(IID\_IPersistFile, &ppf);
         if (SUCCEEDED(hres))
         {   
           WORD wsz\[MAX\_PATH\];
      
           // Set the path to the shell link target.
           hres = psl->SetPath(pszShortcutFile);
      
           if (!SUCCEEDED(hres))
             AfxMessageBox("SetPath failed!");
      
           // Set the description of the shell link.
           hres = psl->SetDescription(pszDesc);
      
           if (!SUCCEEDED(hres))
             AfxMessageBox("SetDescription failed!");
      
           // Ensure string is ANSI.
           MultiByteToWideChar(CP\_ACP, 0, pszLink, -1, wsz, MAX\_PATH);
      
           // Save the link via the IPersistFile::Save method.
           hres = ppf->Save(wsz, TRUE);
      
           // Release pointer to IPersistFile.
           ppf->Release();
         }
         // Release pointer to IShellLink.
         psl->Release();
      }
      return hres;
      

      }

      Deepak Khajuria

      T 1 Reply Last reply
      0
      • D Deepak Khajuria

        The following code should do:

        HRESULT CreateShortcut(LPCSTR pszShortcutFile, LPSTR pszLink,
        LPSTR pszDesc)
        {
        HRESULT hres;
        IShellLink* psl;

        // Get a pointer to the IShellLink interface.
        hres = CoCreateInstance(CLSID\_ShellLink, NULL, CLSCTX\_INPROC\_SERVER,
                                IID\_IShellLink, &psl);
        if (SUCCEEDED(hres))
        {
           IPersistFile\* ppf;
        
           // Query IShellLink for the IPersistFile interface for 
           // saving the shell link in persistent storage.
           hres = psl->QueryInterface(IID\_IPersistFile, &ppf);
           if (SUCCEEDED(hres))
           {   
             WORD wsz\[MAX\_PATH\];
        
             // Set the path to the shell link target.
             hres = psl->SetPath(pszShortcutFile);
        
             if (!SUCCEEDED(hres))
               AfxMessageBox("SetPath failed!");
        
             // Set the description of the shell link.
             hres = psl->SetDescription(pszDesc);
        
             if (!SUCCEEDED(hres))
               AfxMessageBox("SetDescription failed!");
        
             // Ensure string is ANSI.
             MultiByteToWideChar(CP\_ACP, 0, pszLink, -1, wsz, MAX\_PATH);
        
             // Save the link via the IPersistFile::Save method.
             hres = ppf->Save(wsz, TRUE);
        
             // Release pointer to IPersistFile.
             ppf->Release();
           }
           // Release pointer to IShellLink.
           psl->Release();
        }
        return hres;
        

        }

        Deepak Khajuria

        T Offline
        T Offline
        Tommy H D Svensson
        wrote on last edited by
        #3

        Deepak Khajuria wrote: hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, &psl); I get an error when giving &psl to CoCreateInstance... the error disappears when I cast it to a void** pointer... but then the call fails... Actually, what my only wish to do is to get the target path of a link and I know the path to the link. Any ideas?

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups