1 BOOL CFileTool::CreateShortcuts(const CString *pFile, 2 const CString *pPath, 3 const CString *pIconLocation, 4 const CString *pArguments, 5 const CString *pWorkingDirectory, 6 WORD pHotkey, 7 int pShowCmd, 8 const PCIDLIST_ABSOLUTE pIDList, 9 const CString *pRelativePat, 10 const CString *pDescription) 11 { 12 // 入口参数检查 13 if (NULL == pFile || NULL == pPath) 14 { 15 return FALSE; 16 } 17 18 HRESULT hRet; 19 //初始化COM库 20 hRet = ::CoInitialize(NULL); 21 if (hRet != S_OK) //初始化COM库失败,直接返回 22 { 23 return FALSE; 24 } 25 26 IShellLink *psl = NULL; //IShellLink对象指针 27 IPersistFile *ppf = NULL; //IPersisFil对象指针 28 29 //创建IShellLink实例 30 hRet = ::CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, 31 IID_IShellLink, (void**)&psl); 32 if (hRet != S_OK) //初始化COM库失败,直接返回 33 { 34 //释放COM接口 35 ::CoUninitialize(); 36 return FALSE; 37 } 38 39 //从IShellLink对象中获取IPersistFile接口 40 hRet = psl->QueryInterface(IID_IPersistFile, (void**)&ppf); 41 if (hRet != S_OK) //初始化COM库失败,直接返回 42 { 43 //释放IShellLink对象 44 psl->Release(); 45 //释放COM接口 46 ::CoUninitialize(); 47 return FALSE; 48 } 49 50 //1.设置快捷方式中的程序路径 51 psl->SetPath(*pPath); 52 53 //2.设置图标 54 if (pIconLocation != NULL && pIconLocation[0] != L'