(*
/*

CLASS {NATIVE_Shortcut_info|_Delphi_VCL},
NATIVE, ABSTRACT:
*/
*)

unit NATIVE_Shortcut_info;

interface uses Windows, shlobj, ShellAPI, ActiveX, ComObj;

function Call_Resolve_link(const Path_link: String): String;
procedure MakeShortcut(const filename, target_filename,
		arguments, workdir: String);

implementation

const
  IID_IPersistFile: TGUID = (
    D1:$0000010B;D2:$0000;D3:$0000;D4:($C0,$00,$00,$00,$00,$00,$00,$46));
const
    SLR_NOSEARCH  = $10;
	SLR_NOTRACK	  = $20;

function ResolveLink(
const LinkName: String; var FileName: String; 
    DialogParentWnd: HWND ): Boolean;
var
  SLink   : IShellLink;
  PFile   : IPersistFile;
  WFileName : WideString;
  Wnd: HWnd;
  Flg: DWORD;
  Buf: array[ 0..4095 ] of Char;
  FD: TWin32FindData;
begin
  Result := FALSE;
  CoInitialize( nil );
  if  CoCreateInstance( TGUID( CLSID_ShellLink ), nil, CLSCTX_INPROC_SERVER,
                        TGUID( IID_IShellLinkA ), SLink ) <> S_OK then Exit;
  if  SLink.QueryInterface( System.TGUID( IID_IPersistFile ), PFile )
      <> S_OK then Exit;
  WFileName := LinkName;
  PFile.Load(PWChar(WFileName),STGM_READ);
  Wnd := DialogParentWnd;
  Flg := SLR_UPDATE;
  if  Wnd = THandle( -1 ) then
  begin
      Wnd := 0;
      Flg := SLR_NOUPDATE or SLR_NO_UI
          or SLR_NOTRACK or SLR_NOSEARCH;
  end;
  if  (Wnd = 0) or (SLink.Resolve( Wnd, Flg ) = NOERROR) then
  begin
    if   SLink.GetPath( Buf, Sizeof( Buf ) div Sizeof( Char ),
         PWin32FindData(@ FD)^
         , 0 ) <> NOERROR then
         FileName := ''
    else FileName := Buf;
    if  Filename <> '' then
        if SLink.GetArguments( Buf, Sizeof( Buf ) ) <> NOERROR then Exit;
    Result := TRUE;
  end;
end;


function Call_Resolve_link(const Path_link: String): String;
var Filename: String;
begin
    Result := '';
    if ResolveLink( Path_link, Filename, 0 ) then
        Result := Filename;
end;

procedure MakeShortcut(const filename, target_filename,
		arguments, workdir: String);
var SLink: IShellLink;
	AnObj: IUnknown;
	PFile: IPersistFile;
begin
	AnObj := CreateComObject (CLSID_ShellLink);
	SLink := AnObj as IShellLink;
	PFile := AnObj as IPersistFile;
		
	SLink.SetPath(PChar(target_filename));
	SLink.SetWorkingDirectory(PChar(workdir));
	SLink.SetArguments(PChar(arguments));
	PFile.Save(PWideChar(WideString( filename )), true);
end;



end.
(*
/*
CONST STR : NATIVE_Import_native_shortcut_info = @
            "uses NATIVE_Shortcut_info;"

            NATIVE_Resolve_link = @
            "   RESULT := Call_Resolve_link(X_Path);" 
            
            
            NATIVE_Create_link = @
            "	MakeShortcut(X_Path,X_Target,X_Arguments,X_Work);"
            .

END
*/
*)
