BOOL CDlg::CreateDesktopShotCut(CString strName, CString strSourcePath) { if (FAILED(CoInitialize(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_DESKTOPDIRECTORY,&pidl))) { if(!SHGetPathFromIDList(pidl,Path)) { pShell->Free(pidl); } pShell->Release(); strDestDir.Format(_T("%s"),Path); strDestDir+= _T("\\"); strDestDir+= strName;//設置桌面快捷方式的名字 strDestDir+= _T(".lnk"); IShellLink* psl; if(SUCCEEDED(CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID*)&psl))) { psl->SetPath(strSourcePath + _T("Player.exe"));//設置快捷方式的目標位置 //比如目標位置為C:\windows\a.txt 起始位置就應該設置為C:\windows否則會導致不可預料的錯誤 //