您的位置:首页 > 运维架构 > 网站架构

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: