unit ShellUtils;
interface
uses
	ShlObj, ActiveX;


function PIDL_GetSize(aPIDL: PItemIDList): Integer;
procedure PIDL_Append(aMalloc: IMalloc; var aDst: PItemIDList; const aSrc: PItemIDList);

implementation

function PIDL_GetSize(aPIDL: PItemIDList): Integer;
var
	aP: PShItemID;
	aSize: Integer;
begin
	aP := PShItemID(aPIDL);
	Result := 0;
	if Assigned(aP) then begin
		aSize := aP.cb;
		while aSize > 0 do begin
			Inc(Result, sizeof(aP.cb) + aSize);
			Inc(Longint(aP), sizeof(aP.cb) + aSize);
			aSize := aP.cb
		end;
	end;
end;

procedure PIDL_Append(aMalloc: IMalloc; var aDst: PItemIDList; const aSrc: PItemIDList);
var
	aDstSize,
	aSrcSize,
	aNewSize: Integer;
begin
	aDstSize := PIDL_GetSize(aDst);
	aSrcSize := PIDL_GetSize(aSrc);
	aNewSize := aDstSize + aSrcSize;
	if aNewSize = 0 then
		if Assigned(aDst) then
			aDst := aMalloc.Realloc(aDst, 0)
		else
	else begin
		aDst := aMalloc.Realloc(aDst, aNewSize + sizeof(Word));
		Move(aSrc^, Pointer(Longint(aDst) + aDstSize)^, aSrcSize);
		Word(Pointer(Longint(aDst) + aNewSize)^) := 0;
	end;
end;
		
end.
 