title: what is icon index?
body: <p>I am trying to programmatically creating a Shell link, i.e. a shortcut. In Visual Studio C++.</p>
  
  <p>The shortcut is created, and it works. But the icon is the default one (because the provided icon was not taken in account by the API). Reading the docs, it appears that I have to provide a icon <em>index</em>. But what is this? For now there is only a .ico file.</p>
  
  <p>Here is the code (see the ### lines)</p>
  
  <pre><code>#include "stdafx.h"
  #include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;ShlObj.h&gt;
  
  class MakeLnk
  {
  
     public:
        MakeLnk(){}
        void SetLnkInfos
       (
       std::wstring i_target,
       std::wstring i_args,
       std::wstring i_savePath,
       std::wstring i_description,
       std::wstring i_icoloc
       )
    {
       target = i_target;
       args = i_args; 
       savePath = i_savePath;
       description = i_description;
       icolocation = i_icoloc;
    }
  
    // Utility function, to create a link
    HRESULT CreateLnk()
    {
       LPCWSTR lpszPathObj = target.c_str();
       LPCTSTR arguments = args.c_str();
       LPCWSTR lpszLinkPath = savePath.c_str();
       LPCWSTR lpszDesc = description.c_str();
  // ##########################
       LPCWSTR lpszIcoPath = icolocation.c_str(); // a path like "C:\\tmp\\crab.ico"
  // ##########################
  
       HRESULT hres;
       IShellLink* psl;
       CoInitialize(NULL);
       // Get a pointer to the IShellLink interface. It is assumed that CoInitialize
       // has already been called.
       hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID*)&amp;psl);
       if (SUCCEEDED(hres))
       {
          IPersistFile* ppf;
  
          // Set the path to the shortcut target and add description and args. 
          psl-&gt;SetPath(lpszPathObj);
          psl-&gt;SetDescription(lpszDesc);
          psl-&gt;SetArguments(arguments);
  // ###############################################
          psl-&gt;SetIconLocation(lpszIcoPath, 0); // HERE! WHAT TO PUT INSTEAD OF "0" ?
  // ###############################################
          // Query IShellLink for the IPersistFile interface, used for saving the 
          // shortcut in persistent storage. 
          hres = psl-&gt;QueryInterface(IID_IPersistFile, (LPVOID*)&amp;ppf);
  
          if (SUCCEEDED(hres))
          {
             // Save the link by calling IPersistFile::Save. 
             hres = ppf-&gt;Save(lpszLinkPath, TRUE);
             ppf-&gt;Release();
          }
          psl-&gt;Release();
       }
       CoUninitialize();
       return hres;
    }
  
  private:
    std::wstring target, args, savePath, description;
    std::wstring icolocation;
  };
  
  
  int main()
  {
      MakeLnk linkMaker;
      std::wstring exepath(L"C:\\Program Files\\Crab\\Exec.exe"), arguments(L"eat dance"), lnkPath(L"shortcut.lnk"), description(L"Click here to lanch the crab program"), icon(L"C:\\tmp\\crab.ico");
      linkMaker.SetLnkInfos(exepath, arguments, lnkPath, description, icon);
      bool res = linkMaker.CreateLnk();
      return res ? 0 : -1;
  }
  </code></pre>