procedure TForm1.CreateShortCutOnDesktop(var
sExeName,sDirPath
:string);
{
Parameters :- sExeName = Program name and sDirPath = Directory Path
}
var tmpObject :
Unknown;
tmpSLink :
ShellLink;
tmpPFile :
PersistFile;
PIDL
: PItemIDList;
ShortCutDirectory : array[0..255]
of char;
ShortCutFileName :
WideString;
sTemp: String;
begin
{ Create a COM object,
initialise to ShellLink interface}
tmpObject :=
createComObject(CLSID_ShellLink);
tmpSLink := tmpObject as
IShellLink;
tmpPFile := tmpObject as
IPersistFile;
{ Create Shortcut ICON on the
Desktop}
tmpSLink.SetPath(pChar(sExeName));
tmpSLink.SetWorkingDirectory(pChar(sDirPath));
SHGetSpecialFolderLocation(0,CSIDL_DESKTOP,PIDL);
SHGetPathFromIDList(PIDL,ShortCutDirectory);
sTemp := '\' + ChangeFileExt(ExtractFileName(sExeName),
'.lnk');
ShortcutFilename := ShortcutDirectory + sTemp;
tmpPFile.Save(pWChar(ShortcutFilename),
FALSE);
Use the above code should be ok. Please avoid typing mistakes by
cutting and pasting the
code.
{ Error here
-------------------
{--->
ShortCutFileName := ShortCutDirectory + '\' + { produces
an"Incompatible types" error}
{ If I comment out the " + '\' " code then
the "Incompatibe types" error is fixed but the
following part of the line produces an
error "not enough actual
parameters", (which may be caused by the missing "\" of
course) }
ChangeFileExt(ExtractFileName(sEXEName),'lnk' ) ;
-------------------------------}
tmpPFile.Save(pWChar(ShortcutFileName), FALSE ) ;
end;
The program will not compile as shown for the
line marked {--->