Announcement

Collapse
No announcement yet.

CreateShortCut -- iShellLink

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • CreateShortCut -- iShellLink

    I am using the following code to create a shortcut (thanks to whomever created it).

    My question is... How were the offets for each method calculated? I'd like to use the SetIconLocation() method to set a different icon than the default one.

    --Dave

    Code:
    SUB CreateLink (BYVAL CSIDL AS LONG, LnkName AS ASCIIZ, _
                   ExePath AS ASCIIZ, Arguments AS ASCIIZ, WorkDir AS ASCIIZ, _
                   BYVAL ShowCmd AS DWORD, Comment AS ASCIIZ)
     
      LOCAL TmpAsciiz AS ASCIIZ * %MAX_PATH, TmpWide AS ASCIIZ * (2 * %MAX_PATH)
      LOCAL psl AS DWORD PTR, ppf AS DWORD PTR, pp AS DWORD PTR, lResult AS DWORD
      LOCAL CLSID_ShellLink AS GUID, IID_IShellLink AS GUID, _
            CLSCTX_INPROC_SERVER AS DWORD, IID_Persist AS GUID
     
      DEFINE_OLEGUID CLSID_ShellLink, &H00021401, 0, 0
      DEFINE_OLEGUID IID_IShellLink,  &H000214EE, 0, 0
      DEFINE_OLEGUID IID_Persist,     &H0000010B, 0, 0
     
      CLSCTX_INPROC_SERVER = 1
     
      CoInitialize %Null
     
      IF ISFALSE(CoCreateInstance (CLSID_ShellLink, %Null, CLSCTX_INPROC_SERVER, IID_IShellLink, psl)) THEN
         pp = @psl + 80: CALL DWORD @pp USING Sub2 (BYVAL psl, ExePath)       '21
         pp = @psl + 44: CALL DWORD @pp USING Sub2 (BYVAL psl, Arguments)     '12
         pp = @psl + 36: CALL DWORD @pp USING Sub2 (BYVAL psl, WorkDir)       '10
         pp = @psl + 60: CALL DWORD @pp USING Sub2 (BYVAL psl, BYVAL ShowCmd) '16
         pp = @psl + 28: CALL DWORD @pp USING Sub2 (BYVAL psl, Comment)       '8
         pp = @psl: CALL DWORD @pp USING Sub3 (BYVAL psl, IID_Persist, ppf) TO lResult
         IF lResult = 0 THEN
            DIM pidl AS DWORD
            TmpAsciiz = CURDIR$
            IF ISFALSE(SHGetSpecialFolderLocation(BYVAL %HWND_DESKTOP, BYVAL CSIDL, BYVAL VARPTR(pidl))) THEN
               SHGetPathFromIDList BYVAL pidl, TmpAsciiz
               CoTaskMemFree BYVAL pidl
            END IF
            TmpAsciiz = TmpAsciiz + "\" + LnkName + ".Lnk"
            MultiByteToWideChar %CP_ACP, 0, TmpAsciiz, -1, TmpWide, %MAX_PATH
            pp = @ppf + 24
            CALL DWORD @pp USING Sub3 (BYVAL ppf, TmpWide, BYVAL %True)
            pp = @ppf + 8
            CALL DWORD @pp USING Sub1 (BYVAL ppf)
         END IF
         pp = @psl + 8: CALL DWORD @pp USING Sub1 (BYVAL psl)
      END IF
     
      CoUninitialize
     
    END SUB

    ------------------
    Home of the BASIC Gurus
    www.basicguru.com
    Home of the BASIC Gurus
    www.basicguru.com

  • #2
    Dave --
    see left remarks
    Code:
    #define INTERFACE   IShellLinkA
    
    DECLARE_INTERFACE_(IShellLinkA, IUnknown)       // sl
    {
        // *** IUnknown methods ***
    0   STDMETHOD(QueryInterface) (THIS_ REFIID riid, LPVOID * ppvObj) PURE;
    4   STDMETHOD_(ULONG,AddRef) (THIS)  PURE;
    8   STDMETHOD_(ULONG,Release) (THIS) PURE;
    
        // *** IShellLink methods ***
    12  STDMETHOD(GetPath)(THIS_ LPSTR pszFile, int cchMaxPath, WIN32_FIND_DATAA *pfd, DWORD fFlags) PURE;
    
    16  STDMETHOD(GetIDList)(THIS_ LPITEMIDLIST * ppidl) PURE;
    20  STDMETHOD(SetIDList)(THIS_ LPCITEMIDLIST pidl) PURE;
    
    24  STDMETHOD(GetDescription)(THIS_ LPSTR pszName, int cchMaxName) PURE;
    28  STDMETHOD(SetDescription)(THIS_ LPCSTR pszName) PURE;
    
    32  STDMETHOD(GetWorkingDirectory)(THIS_ LPSTR pszDir, int cchMaxPath) PURE;
    36  STDMETHOD(SetWorkingDirectory)(THIS_ LPCSTR pszDir) PURE;
    
    40  STDMETHOD(GetArguments)(THIS_ LPSTR pszArgs, int cchMaxPath) PURE;
    44  STDMETHOD(SetArguments)(THIS_ LPCSTR pszArgs) PURE;
    
    48  STDMETHOD(GetHotkey)(THIS_ WORD *pwHotkey) PURE;
    52  STDMETHOD(SetHotkey)(THIS_ WORD wHotkey) PURE;
    
    56  STDMETHOD(GetShowCmd)(THIS_ int *piShowCmd) PURE;
    60  STDMETHOD(SetShowCmd)(THIS_ int iShowCmd) PURE;
    
    64  STDMETHOD(GetIconLocation)(THIS_ LPSTR pszIconPath, int cchIconPath, int *piIcon) PURE;
    68  STDMETHOD(SetIconLocation)(THIS_ LPCSTR pszIconPath, int iIcon) PURE;
    
    72  STDMETHOD(SetRelativePath)(THIS_ LPCSTR pszPathRel, DWORD dwReserved) PURE;
    
    76  STDMETHOD(Resolve)(THIS_ HWND hwnd, DWORD fFlags) PURE;
    
    80  STDMETHOD(SetPath)(THIS_ LPCSTR pszFile) PURE;
    };

    ------------------
    E-MAIL: [email protected]

    Comment


    • #3
      Thanks Semen!

      What file did you get the definition from? SHLDISP.H?

      --Dave


      ------------------
      Home of the BASIC Gurus
      www.basicguru.com
      Home of the BASIC Gurus
      www.basicguru.com

      Comment


      • #4
        SHLOBJ.H

        ------------------
        E-MAIL: [email protected]

        Comment


        • #5
          Dave, Semen, Is this more reliable for creating desktop
          shortcuts than the code semen posted several months ago
          in the Console Compiler section ?

          That code which I use and only changing the applicable
          variable works most of the time but have had reports of
          it not creating the shortcut or creating one that has
          no information in it.

          If it is more reliable, could you post a small snippet that
          defines the variables and called the sub? and can it be used
          in pbcc ?
          thanks

          ------------------
          Client Writeup for the CPA

          buffs.proboards2.com

          Links Page

          Comment


          • #6
            fred --
            original code was posted in http://www.powerbasic.com/support/pb...ad.php?t=24977
            (assembled from msdn & florent's program)
            this code can be used in pb/cc also.


            ------------------
            e-mail: [email protected]

            Comment

            Working...
            X