BoxedApp Blog

BoxedApp: Tips'n'Tricks, Examples, Use Cases etc.

BoxedApp Packer 2019.2, BoxedApp SDK 2019.1

We are excited to announce that we’ve just released BoxedApp Packer 2019.2 and BoxedApp SDK 2019.1:

  • FIX: GetFinalPathNameByHandle() failed for virtual files located on virtual drive.
  • FIX: if input exe required administrative privileges, packed exe didn’t require administrative privileges.

New tutorial is ready: packaging .NET Core application into a single executable file package.

Delphi: why TStreamAdapter is not suitable for IStream-based virtual files?


One delphi programmer wrote me that he tried to create a IStream-based virtual file using a TStreamAdapter. But it doesn’t work. Why?

The reason is quite simple: TStreamAdapter doesn’t provide a correct implementation of IStream.Clone. Check Classes.pas:

function TStreamAdapter.Clone(out stm: IStream): HResult;
  Result := E_NOTIMPL;

IStream.Clone is important method, BoxedApp SDK uses it. But TStreamAdapter just returns E_NOTIMPL. OK, but what’s the solution?

The solution is to create a new class derived from TStreamAdapter and implement IStream.Clone.

For example, if you need a TStreamAdapter based on TFileStream, the implementation would be the following:

  TCloneSA = class(TStreamAdapter)
    Path: String;
    function Clone(out stm: IStream): HResult; override; stdcall;
    destructor Destroy; override;

  { TCloneSA }

function TCloneSA.Clone(out stm: IStream): HResult;
  FS: TFileStream;
  S: TCloneSA;
  FS := TFileStream.Create(Path, fmOpenReadWrite or fmShareDenyNone);
  S := TCloneSA.Create(FS, soOwned);
  S.Path := Path;

  result := S.QueryInterface(IStream, stm);