Article View: borland.public.cppbuilder.deployment
Article #62Re: How to Create a Shortcut File
From: JF Jolin
Date: Wed, 28 Feb 2007 19:35
Date: Wed, 28 Feb 2007 19:35
88 lines
3648 bytes
3648 bytes
28 Feb 2007 02:14:20 -0500, sugi <trskopo@yahoo.com> wrote:
> How to do that?
// CreateLink - uses the Shell's IShellLink and IPersistFile interfaces
// to create and store a shortcut to the specified object.
//
// Parameters:
// LPCSTR lpszLinkTo, - File creating shortcut for
// LPCSTR lpszCreateLink, - Name and path for the shortcut
// LPCSTR lpszDesc, - Description of Shortcut (Comment) Shows in Hint
// LPCSTR lpszWorkDir, - Working Directory for lpszLinkTo
// LPCSTR lpszArguments - Arguments for lpszLinkTo
// int iShow - Window state to show 1-Normal, 3-Maximized, 7-Minimized
// SW_SHOWNORMAL, SW_MAXIMIZE, SW_MINIMIZE
// WORD wHotKey - Hot key for the shortcut
//
//
HRESULT __stdcall CreateLink(LPCSTR lpszLinkTo,
LPCSTR lpszCreateLink,
LPCSTR lpszDesc,
LPCSTR lpszWorkDir,
LPCSTR lpszArguments,
int iShow,
WORD wHotKey)
{
HRESULT hres;
IShellLink *psl;
CoInitialize(NULL);
// Get a pointer to the IShellLink interface.
hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID *) &psl);
if (SUCCEEDED(hres)) {
IPersistFile *ppf;
// The File to create a Link To eg: the executable
psl->SetPath(lpszLinkTo);
// Description
psl->SetDescription(lpszDesc);
// Working Directory
psl->SetWorkingDirectory(lpszWorkDir);
// Arguments
psl->SetArguments(lpszArguments);
// Window State (SHOW)
psl->SetShowCmd(iShow);
// Hot Key / Shortcut Key
psl->SetHotkey(wHotKey);
// Query IShellLink for the IPersistFile interface
// for saving the shortcut in persistent storage.
hres = psl->QueryInterface((_GUID) IID_IPersistFile, (void **) &ppf);
if (SUCCEEDED(hres)) {
WCHAR wsz[MAX_PATH];
// IPersistFile::Save parameter's LPCOLESTR is defined as LPCWSTR for Win32 in <mapinls.h>
// Ensure that the string is Unicode.
MultiByteToWideChar(CP_ACP, 0, lpszCreateLink, -1, wsz, MAX_PATH);
// Save the link by calling IPersistFile::Save.
hres = ppf->Save(wsz, TRUE);
ppf->Release();
}
psl->Release();
}
CoUninitialize();
return hres;
}
Best regards
__
JF Jolin
Technical Details
Message-ID:
<op.tog4pzwjjr09w3@localhost>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news3.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<45e52bcc$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: f8e54,595d3f565282bbb X-Google-Attributes: gidf8e54,public X-Google-Language: ENGLISH,ASCII-7-bit Date: Wed, 28 Feb 2007 14:35:49 -0500 Subject: Re: How to Create a Shortcut File From: "JF Jolin" <jfj@nospam.com> Content-Type: text/plain; charset=iso-8859-15 MIME-Version: 1.0 Newsgroups: borland.public.cppbuilder.deployment References: <45e52bcc$1@newsgroups.borland.com> Content-Transfer-Encoding: Quoted-Printable Message-ID: <op.tog4pzwjjr09w3@localhost> User-Agent: Opera Mail/9.02 (Win32) NNTP-Posting-Host: 66.36.136.121 X-Trace: newsgroups.borland.com 1172691340 66.36.136.121 (28 Feb 2007 11:35:40 -0800) Lines: 88 Path: arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news3.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail