c++ windows 创建快捷方式
2013-06-03 14:14
190 查看
创建一个exe程序的快捷方式
记得一定要先定义初始化,同时检测函数的返回值,这是一个好习惯!
VS2012 亲测,完美通过。
希望对大家有用处
记得一定要先定义初始化,同时检测函数的返回值,这是一个好习惯!
BOOL createShortcut(LPCTSTR pszExePath,LPCTSTR pszWorkingDir, LPCTSTR pszDescription, LPCTSTR pszIconPath, LPCTSTR pszDestinationPath) { CoInitialize(NULL); IShellLink* pShellLink = NULL; HRESULT hres; hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_ALL, IID_IShellLink, (void**)&pShellLink); std::cout<< std::hex << hres <<std::endl; if (SUCCEEDED(hres)) { pShellLink->SetPath(pszExePath); pShellLink->SetDescription(pszDescription); pShellLink->SetIconLocation(pszIconPath,0); pShellLink->SetWorkingDirectory(pszWorkingDir); IPersistFile *pPersistFile; hres = pShellLink->QueryInterface(IID_IPersistFile, (void**)&pPersistFile); if (SUCCEEDED(hres)) { hres = pPersistFile->Save(pszDestinationPath,TRUE); pPersistFile->Release(); } else { std::cout<<"ERRO 2"<<std::endl; return FALSE; } pShellLink->Release(); } else { std::cout<<"ERRO 1"<<std::endl; return FALSE; } CoUninitialize(); return TRUE; }
VS2012 亲测,完美通过。
希望对大家有用处
相关文章推荐
- VS2010安装部署打包说明(快捷方式创建和卸载设置)
- Android创建和删除桌面快捷方式
- 在应用程序中创建快捷方式
- 自动创建文件快捷方式
- InstallShield工程中如何使得动态文件链接方式也可以创建快捷方式
- 用js javascript 创建网页快捷方式
- .NET 应用程序中创建桌面快捷方式
- 用js文件创建一个带参数的view client的快捷方式(类似的bat形式也可模仿实现),并实现自动登录
- 使用代码创建快捷方式
- C# WinForm创建包含备注的快捷方式实例
- [转]Linux下创建桌面快捷方式
- ubuntu12.04创建程序的快捷方式
- ubuntu android-studio创建右侧快捷启动方式
- 创建快捷方式
- Linux 下 eclipse 创建快捷方式
- ubuntu 下创建桌面快捷方式
- 在 Linux创建快捷方式
- VC++创建快捷方式
- [android]为程序创建快捷方式
- linux 下给navicat premium创建桌面快捷方式