/ / Create shortcuts // pazsrcpath in the desktop or start menu: Source file path // bdesktop: flag, use to create shortcuts on the desktop, really, create on the desktop, otherwise create in the start menu
Bool Createshortcut (Const Char * Pszsrcpath, Bool Bdesktop) {Coinitialize (NULL);
Bool Bret = false; ishelllink * psl; lpitemidlist pidl; lpmalloc pshellmalloc; std :: string string strdesktoppath; std :: string string strstartMenupath;
Const int NFolder [2] = {CSIDL_DESKTOPDIRECTORY, CSIDL_STARTMENU};
IF (SucceEded (Surgetmalloc (& Pshellmalloc)) {char path [max_path 1]; for (int i = 0; i <2; i ) {if (Succeeded (SUCCEEDED (NULL, NFOLDER [I], & PIDL))))) {IF (SHGETPATHFROMIDLIST (PIDL, PATH)) {IF (i == 0) strdesktoppath = path; else strstartMalluPath = path;} pshellmalloc-> free (PIDL);}} pshellmalloc-> release ();
Char szfileTitle [max_path] = {0}; :: getFileTitle (pszsrcpath, szfiletitle, max_path);
Std :: string str; if (bdesktop) str = strdesktoppath; else str = strStartMenuPath;
Str = "//"; str = std :: string (SZFileTitle); Str = ".lnk";
HRESULT hr = CoCreateInstance (CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID *) & psl); if (SUCCEEDED (hr)) {IPersistFile * ppf; psl-> SetPath (pszSrcPath); psl-> SetDescription ( "Shortcut created by custom code "); psl-> SetShowCmd (SW_SHOW); if (SUCCEEDED (psl-> QueryInterface (IID_IPersistFile, (LPVOID *) & ppf))) {WORD mbw [MAX_PATH]; MultiByteToWideChar (CP_ACP, MB_PRECOMPOSED, str.c_str (), -1, MBW, Max_Path; if (ppf-> save (mbw, true))) Bret = true; PPF-> Release ();} PSL-> Release ();} couninitialize ();
Return Bret;