Article View: be.comp.programming
Article #8166Re: maken snelkoppeling via winapi
From: Dries Deschout
Date: Mon, 08 Jul 2002 14:47
Date: Mon, 08 Jul 2002 14:47
64 lines
2938 bytes
2938 bytes
"edg" <edg@skynet.be> schreef in bericht
news:3d295c32$0$315$ba620e4c@news.skynet.be...
> Beste,
> weet er ieman hoe ik software matig een snelkoppeling kan maken via
winapi.
> Ik gebruik bcb.
> etienne
Bij deze een voorbeeldje uit de 'Win32 Developer's References' (topic: Shell
Link)
(toch eens in kijken ;-) )
Dries Deschout
// 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;
}
Technical Details
Message-ID:
<3d29a5d7$0$338$ba620e4c@news.skynet.be>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-05!sn-xit-08!supernews.com!news.infoave.net!skynet.be!skynet.be!louie!not-for-mailReferences:
<3d295c32$0$315$ba620e4c@news.skynet.be>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fcea4,24bc8f324c8fe090 X-Google-Attributes: gidfcea4,public X-Google-ArrivalTime: 2002-07-08 07:48:22 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-05!sn-xit-08!supernews.com!news.infoave.net!skynet.be!skynet.be!louie!not-for-mail From: "Dries Deschout" <driesdeschout@subdimension.com> Newsgroups: be.comp.programming References: <3d295c32$0$315$ba620e4c@news.skynet.be> Subject: Re: maken snelkoppeling via winapi Date: Mon, 8 Jul 2002 16:47:00 +0200 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 Lines: 67 Message-ID: <3d29a5d7$0$338$ba620e4c@news.skynet.be> Organization: -= Skynet Usenet Service =- NNTP-Posting-Host: 80.200.5.59 X-Trace: 1026139607 reader1.news.skynet.be 338 80.200.5.59 X-Complaints-To: abuse@skynet.be