desktop shortcut
-
I need to create a shortcut on the desktop by my program note: I Know nothing about shell programming:confused: thanks in advance MR.Byte
The following code should do:
HRESULT CreateShortcut(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;
}
Deepak Khajuria
-
The following code should do:
HRESULT CreateShortcut(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;
}
Deepak Khajuria
Deepak Khajuria wrote: hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, &psl); I get an error when giving &psl to CoCreateInstance... the error disappears when I cast it to a void** pointer... but then the call fails... Actually, what my only wish to do is to get the target path of a link and I know the path to the link. Any ideas?