Thema: Delphi IShellLink-Problem

Einzelnen Beitrag anzeigen

CalganX

Registriert seit: 21. Jul 2002
Ort: Bonn
5.403 Beiträge
 
Turbo Delphi für Win32
 
#6

Re: IShellLink-Problem

  Alt 16. Jul 2003, 18:27
Nicht großartig verändert:
Delphi-Quellcode:
function CreateShortcut(const sTargetPath: string;
                          const sParams: string;
                          const sOutput: string;
                          const sExecPath: string): boolean;
const
  IID_IPersistFile: TGUID = '{0000010b-0000-0000-C000-000000000046}';

var
  slShellLink : IShellLink;
  pfPersistFile : IPersistFile;
  wszShortCut : PWideChar;
  hRes : HResult;
  sShortCut : string;
  dwLen : DWORD;

begin
  Result := false;

  hRes := CoCreateInstance(CLSID_ShellLink, nil, CLSCTX_INPROC_SERVER, IID_IShellLinkA, slShellLink);
  if hRes <> S_OK then begin
    exit;
  end;
  slShellLink.SetPath(PChar(sTargetPath));
  slShellLink.SetArguments(PChar(sParams));
  hRes := slShellLink.QueryInterface(IID_IPersistFile,pfPersistFile);
  if hRes <> S_OK then begin
    exit;
  end;
  dwLen := (MAX_PATH+1)*2;
  wszShortcut := AllocMem(dwLen);
  try
    sShortCut := sOutput;
    StringToWideChar(sShortCut,wszShortCut,dwLen);
    hRes := pfPersistFile.Save(wszShortCut, TRUE);
  finally
    FreeMem(wszShortCut,dwLen);
  end;
  Result := (hRes = S_OK);
end;
Chris
  Mit Zitat antworten Zitat