Mail Archives: cygwin/1998/05/10/08:54:47
This is not purely a gnuwin question but related:
How do I create a shortcut for a file? I found the attached program
in one of the WIN32 API helpfiles but gcc doesn't like it. I also
could not find which library exports the IShell stuff.
Is this the only way to make a shortcut? Looks extremely cumbersome to
me. Just to make it clear: I don't want a symbolic link but a real .LNK
file.
Anyway, here goes:
#include <windows.h>
// CreateLink - uses the shell's IShellLink and IPersistFile interfaces
// to create and store a shortcut to the specified object.
// Returns the result of calling the member functions of the interfaces.
// lpszPathObj - address of a buffer containing the path of the object
// lpszPathLink - address of a buffer containing the path where the
// shell link is to be stored
// lpszDesc - address of a buffer containing the description of the
// shell link
HRESULT CreateLink(LPCSTR lpszPathObj,
LPSTR lpszPathLink, LPSTR lpszDesc)
{
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;
// Set the path to the shortcut target, and add the
// description.
psl->lpVtbl->SetPath(psl, lpszPathObj);
psl->lpVtbl->SetDescription(psl, lpszDesc);
// Query IShellLink for the IPersistFile interface for saving the
// shortcut in persistent storage.
hres = psl->lpVtbl->QueryInterface(psl, &IID_IPersistFile,
&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->lpVtbl->Save(ppf, wsz, TRUE);
ppf->lpVtbl->Release(ppf);
}
psl->lpVtbl->Release(psl);
}
return hres;
}
And that is what I get:
BASH.EXE-2.01$ gcc shortc.c
shortc.c: In function `CreateLink':
shortc.c:16: `IShellLink' undeclared (first use this function)
shortc.c:16: (Each undeclared identifier is reported only once
shortc.c:16: for each function it appears in.)
shortc.c:16: `psl' undeclared (first use this function)
shortc.c:19: `CLSID_ShellLink' undeclared (first use this function)
shortc.c:20: `CLSCTX_INPROC_SERVER' undeclared (first use this function)
shortc.c:20: `IID_IShellLink' undeclared (first use this function)
shortc.c:22: `IPersistFile' undeclared (first use this function)
shortc.c:22: `ppf' undeclared (first use this function)
shortc.c:32: `IID_IPersistFile' undeclared (first use this function)
BASH.EXE-2.01$
Thanks for ideas,
Michael
--
Michael Lemke
Sternwarte Bamberg, University of Erlangen-Nürnberg, Germany
(michael AT astro DOT as DOT utexas DOT edu or ai26 AT a400 DOT sternwarte DOT uni-erlangen DOT de)
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request AT cygnus DOT com" with one line of text: "help".
- Raw text -