windows创建快捷方式和快捷网站链接
2014-05-08 15:12
591 查看
#include "shobjidl.h"
#include "shlobj.h"
HRESULT CreateLink(LPCSTR lpszPathObj, LPCSTR lpszPathLink, LPCSTR lpszDesc)
{
HRESULT hres;
IShellLink* psl;
// Get a pointer to the IShellLink interface.
hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
IID_IShellLink, (LPVOID*)&psl);
if (SUCCEEDED(hres))
{
IPersistFile* ppf;
// Set the path to the shortcut target and add the description.
psl->SetPath(lpszPathObj);
psl->SetDescription(lpszDesc);
// Query IShellLink for the IPersistFile interface for saving the
// shortcut in persistent storage.
hres = psl->QueryInterface(IID_IPersistFile, (LPVOID*)&ppf);
if (SUCCEEDED(hres))
{
WCHAR wsz[MAX_PATH];
// Ensure that the string is Unicode.
MultiByteToWideChar(CP_ACP, 0, lpszPathLink, -1, wsz, MAX_PATH);
// TODO: Check return value from MultiByteWideChar to ensure
success.
// Save the link by calling IPersistFile::Save.
hres = ppf->Save(wsz, TRUE);
ppf->Release();
}
psl->Release();
}
return hres;
}
网址简单,就一句话:
WritePrivateProfileString("InternetShortcut","URL",lpszLink,lpszPath);
使用该函数需要注意的是lpszPath的后缀是url,最终生成的链接文件的格式如下
[InternetShortcut]
URL=http://www.baidu.com
#include "shlobj.h"
HRESULT CreateLink(LPCSTR lpszPathObj, LPCSTR lpszPathLink, LPCSTR lpszDesc)
{
HRESULT hres;
IShellLink* psl;
// Get a pointer to the IShellLink interface.
hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
IID_IShellLink, (LPVOID*)&psl);
if (SUCCEEDED(hres))
{
IPersistFile* ppf;
// Set the path to the shortcut target and add the description.
psl->SetPath(lpszPathObj);
psl->SetDescription(lpszDesc);
// Query IShellLink for the IPersistFile interface for saving the
// shortcut in persistent storage.
hres = psl->QueryInterface(IID_IPersistFile, (LPVOID*)&ppf);
if (SUCCEEDED(hres))
{
WCHAR wsz[MAX_PATH];
// Ensure that the string is Unicode.
MultiByteToWideChar(CP_ACP, 0, lpszPathLink, -1, wsz, MAX_PATH);
// TODO: Check return value from MultiByteWideChar to ensure
success.
// Save the link by calling IPersistFile::Save.
hres = ppf->Save(wsz, TRUE);
ppf->Release();
}
psl->Release();
}
return hres;
}
网址简单,就一句话:
WritePrivateProfileString("InternetShortcut","URL",lpszLink,lpszPath);
使用该函数需要注意的是lpszPath的后缀是url,最终生成的链接文件的格式如下
[InternetShortcut]
URL=http://www.baidu.com
相关文章推荐
- 软件设计之状态机
- 基于Linux的v4l2视频架构驱动应用编写
- MVVM架构~knockoutjs系列之文本框数符长度动态统计功能
- 成都网站优化公司告诉你百度快照更新频次和排名有什么关系?
- 网站中图片上滑出现说明文字的特效
- 网站导航标题栏下面有一小色块跟随鼠标移动,同时色块颜色改变的特效
- ssl错误 该网站的安全证书不受信任!
- dell 服务器架构I/O高性能的SSD阵列曲折经历
- 所生成项目的处理器架构“MSIL”与引用“***”的处理器架构“x86”不匹配。这种不匹配可能会导致运行时失败。请考虑通过配置管理器...
- SEO入门知识1:网站改版后怎么做SEO
- 【180网站】8-14
- 新辰:网站排名浮动不前 相比竞争者到底缺少了什么?
- 真心不爱做网站
- 好的js特效网站!!!
- 推荐一下名校(哈工大)的资料学习网站
- phpcms医院wap手机网站模板下载
- 在网站制作中随时可用的10个 HTML5 代码片段
- 怎么让网站在浏览器网址前面显示小图标?
- 设置网站二级导航及把二级导航做的好看
- 【工具】5个在线网页规范检查的网站