Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to Create a Shortcut File

6 views
Skip to first unread message

sugi

unread,
Feb 28, 2007, 2:14:20 AM2/28/07
to

Hi all,

I am using BCB 6. I am writing an installer code to setup
my application. During installation, I want my installation
program to create a shortcut file, so when user click
start menu, my application icon will be appeared.
How to do that?

Thanks in advance.

Best regards
Sugi

JF Jolin

unread,
Feb 28, 2007, 2:35:49 PM2/28/07
to
28 Feb 2007 02:14:20 -0500, sugi <trs...@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

sugi

unread,
Mar 1, 2007, 2:36:55 AM3/1/07
to

"JF Jolin" <j...@nospam.com> wrote:
>28 Feb 2007 02:14:20 -0500, sugi <trs...@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.


Thank's a lots
Best Regards
Sugi

0 new messages