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
> 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
Thank's a lots
Best Regards
Sugi