BOOL cdlg::createdesktopshotcut (CString strName, CString strsourcepath) {if (FAILED (NULL))
return FALSE;
BOOL bRet = FALSE;
TCHAR path[max_path+1];
CString Strdestdir;
Lpitemidlist Pidl;
Lpmalloc Pshell; if (SUCCEEDED (Shgetmalloc (&pshell))) {if (Succeeded SHGetSpecialFolderLocation (null,csidl_desktopdirect ORY,&PIDL))) {if (!
SHGetPathFromIDList (Pidl,path)) {pshell->free (pidl);
} pshell->release ();
Strdestdir.format (_t ("%s"), Path);
strdestdir+= _t ("\ \");
strdestdir+= strname;//Set the name of the desktop shortcut strdestdir+= _t (". lnk");
Ishelllink* PSL;
if (SUCCEEDED (CoCreateInstance (Clsid_shelllink, NULL, Clsctx_inproc_server, Iid_ishelllink, (lpvoid*) &PSL)) {Psl->setpath (StrsouRcepath + _t ("Player.exe"))//Set the target position of the shortcut//if the target location is C:\windows\a.txt start position should be set to C:\windows otherwise it will cause unexpected error More Highlights: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/vc///If the folder's shortcuts start and target locations Can be set to the same psl->setworkingdirectory (Strsourcepath);
Sets the starting position of the shortcut ipersistfile* PPF; if (succeeded Psl->queryinterface (Iid_ipersistfile, (lpvoid*) &PPF)) {//wcha
R Wsz[max_path];
MultiByteToWideChar (cp_thread_acp,mb_precomposed, (LPCTSTR) strdestdir,-1,wsz,max_path);//Set the name of the desktop shortcut if (SUCCEEDED (Ppf->save (strdestdir,true))//save shortcut to desktop {Ppf->rele
ASE ();
Psl->release ();
BRet = TRUE;
}else{ppf->release (); Psl->release ();
}}else{ppf->release ();
Psl->release ();
}}} couninitialize ();
if (!bret) {lpvoid lpmsgbuf; FormatMessage (Format_message_allocate_buffer | Format_message_from_system, NULL, GetLastError (), Makelangid (Lang_neutral, SU
Blang_default),//DEFAULT language (LPTSTR) &lpmsgbuf, 0, NULL
);
Display the string.
TRACE (_t ("----------------Create Link Error:%s\r\n"), (tchar*) lpmsgbuf);
_COMNLOG->LOGOUTV (_t ("----------------createdesktopshotcut Failed:%s\r\n"), (tchar*) lpmsgbuf);
Free the buffer.
LocalFree (LPMSGBUF);
return bRet; }