// szStartAppPath : 點擊後啟動的程式// szAddCmdLine : 傳給main函數的lpCmdLine// szDestLnkPath : 捷徑的儲存路徑// szIconPath : 捷徑顯示的表徵圖#ifdef _UNICODE typedef wstring tstring;#else typedef string tstring;#endifbool CreateLinkFile(LPCTSTR szStartAppPath,LPCTSTR szAddCmdLine,LPCTSTR szDestLnkPath,LPCTSTR szIconPath){ HRESULT hr = CoInitialize(NULL); if (SUCCEEDED(hr)) { IShellLink *pShellLink; hr = CoCreateInstance(CLSID_ShellLink, NULL,CLSCTX_INPROC_SERVER, IID_IShellLink, (void**)&pShellLink); if (SUCCEEDED(hr)) { pShellLink->SetPath(szStartAppPath); tstring strTmp = szStartAppPath; int nStart = strTmp.find_last_of(_T("/\\")); pShellLink->SetWorkingDirectory(strTmp.substr(0,nStart).c_str()); pShellLink->SetArguments(szAddCmdLine); if(szIconPath) { pShellLink->SetIconLocation(szIconPath,0); } IPersistFile* pPersistFile; hr = pShellLink->QueryInterface(IID_IPersistFile, (void**)&pPersistFile); if (SUCCEEDED(hr)) { hr = pPersistFile->Save(szDestLnkPath, FALSE); if (SUCCEEDED(hr)) { return true; } pPersistFile->Release(); } pShellLink->Release(); } CoUninitialize(); } return false;}