I created a very simple program to create a shortcut in the desktop,
but it crashes with EOLESysError (nothing else in the error message).
I tryed to google, but it didn't show much. Am I missing some kind of
initialization call that should be made? thanks, here is the full

{ Creates a link to the Windows calculator in the desktop }
program createshortcut;

{$ifdef fpc}{$mode delphi}{$endif}

uses SysUtils, Windows, ShlObj, ActiveX, ComObj;

   IObject: IUnknown;
   ISLink: IShellLink;
   IPFile: IPersistFile;
   PIDL: PItemIDList;
   InFolder: array[0..MAX_PATH] of Char;
   TargetName: String;
   LinkName: WideString;
   TargetName := 'c:\windows\calc.exe';

   { Creates an instance of IShellLink }
   IObject := CreateComObject(CLSID_ShellLink); // Crash here
   ISLink := IObject as IShellLink;
   IPFile := IObject as IPersistFile;

   ISLink.SetPath(pChar(TargetName)) ;
   ISLink.SetWorkingDirectory(pChar(ExtractFilePath(TargetName))) ;

   { Get the desktop location }
   SHGetSpecialFolderLocation(0, CSIDL_DESKTOPDIRECTORY, PIDL) ;
   SHGetPathFromIDList(PIDL, InFolder) ;
   LinkName := InFolder + PathDelim + 'Link created with Free Pascal.lnk';

   { Create the link }
   IPFile.Save(PWChar(LinkName), false);
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org

Reply via email to