http://msdn.microsoft.com/en-us/library/windows/desktop/bb776891(v=vs.85).aspx






#include "stdafx.h"

#include "shortcut.h"


#include "winnls.h"

#include "Shobjidl.h"

#include "Shlobj.h"

#include "shlguid.h"


void Shortcut::make(const wxString& link_filename, const wxString& arg) {

wxString exe_path = wxStandardPaths().GetExecutablePath();

wxString link_path = wxFileName(wxStandardPaths::MSWGetShellDir(CSIDL_DESKTOP), link_filename).GetFullPath();


com_ptr<IShellLinkW> shell_link;

    HRESULT hr = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLinkW, (void**)&*shell_link);

    if (FAILED(hr)) {

stringstream ss;

ss << "Shortcut.make() fail to CoCreateInstance for IID_IShellLinkW. HRESULT : " << hr;

        throw runtime_error(ss.str());

}


shell_link->SetPath(exe_path.wc_str());

    shell_link->SetArguments(arg.wc_str());

//shell_link->SetDescription(desc.wc_str());

//shell_link->SetIconLocation(icon_path, 0);


com_ptr<IPersistFile> persist_file;

    hr = shell_link->QueryInterface(IID_IPersistFile, (void**)&*persist_file);

    if (FAILED(hr)) { 

stringstream ss;

ss << "Shortcut.make() fail to QueryInterface for IID_IPersistFile. HRESULT : " << hr;

        throw runtime_error("");

    }


    hr = persist_file->Save(link_path.wc_str(), TRUE);

    if (FAILED(hr)) { 

        return;

    }

}