[fpc-pascal] EOLESysError calling CreateOLEObject

Felipe Monteiro de Carvalho felipemonteiro.carvalho at gmail.com
Tue Jul 22 14:35:13 CEST 2008


Hello,

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
program.


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

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

uses SysUtils, Windows, ShlObj, ActiveX, ComObj;

var
   IObject: IUnknown;
   ISLink: IShellLink;
   IPFile: IPersistFile;
   PIDL: PItemIDList;
   InFolder: array[0..MAX_PATH] of Char;
   TargetName: String;
   LinkName: WideString;
begin
   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);
end.



More information about the fpc-pascal mailing list