R
!!! MSDN hilft !!!
HRESULT CreateShortCut::CreateIt(LPCSTR pszShortcutFile, LPSTR pszLink,
LPSTR pszDesc)
{
HRESULT hres;
IShellLink* psl;
// Get a pointer to the IShellLink interface.
hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
IID_IShellLink, &psl);
if (SUCCEEDED(hres))
{
IPersistFile* ppf;
// Query IShellLink for the IPersistFile interface for
// saving the shell link in persistent storage.
hres = psl->QueryInterface(IID_IPersistFile, &ppf);
if (SUCCEEDED(hres))
{
WORD wsz[MAX_PATH];
// Set the path to the shell link target.
hres = psl->SetPath(pszShortcutFile);
if (!SUCCEEDED(hres))
AfxMessageBox("SetPath failed!");
// Set the description of the shell link.
hres = psl->SetDescription(pszDesc);
if (!SUCCEEDED(hres))
AfxMessageBox("SetDescription failed!");
// Ensure string is ANSI.
MultiByteToWideChar(CP_ACP, 0, pszLink, -1, wsz, MAX_PATH);
// Save the link via the IPersistFile::Save method.
hres = ppf->Save(wsz, TRUE);
// Release pointer to IPersistFile.
ppf->Release();
}
// Release pointer to IShellLink.
psl->Release();
}
return hres;
}