怎么样通过VC创建快捷方式?

怎么样通过VC创建快捷方式?

创建快捷方式

2004-5-12 0:15:49阅读24次

创建快捷方式
HRESULT CreateLink(LPCSTR lpszPathObj,
LPSTR lpszPathLink,
LPSTR lpszDesc)
{
HRESULT hres;
IShellLink* psl;
CoInitialize(NULL);
// Get a pointer to the IShellLink interface.
hres = CoCreateInstance(CLSID_ShellLink, NULL,
CLSCTX_INPROC_SERVER,
IID_IShellLink,
(void **)&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, (void **)&ppf);
if (SUCCEEDED(hres))
{
WORD wsz[MAX_PATH]; // Ensure that the string is ANSI.
MultiByteToWideChar(CP_ACP, 0, lpszPathLink, -1,wsz, MAX_PATH);
// Save the link by calling IPersistFile::Save.
hres = ppf->Save(wsz, TRUE);
ppf->Release();
}
psl->Release();
}
return hres;
}