{$R 'res\resources.res'}

program Sample01_LaunchEXEFromMemory;

uses
  Forms,
  BoxedAppSDK_Static in '..\..\!Common\BoxedAppSDK_Static.pas', 
  Windows, SysUtils, Classes;

{$R *.RES}

var
   hVirtualFile: THandle;
   HandleStream: THandleStream;
   ResourceStream: TResourceStream;

begin
  Application.Initialize;

  BoxedAppSDK_Init;

   hVirtualFile:= BoxedAppSDK_CreateVirtualFile('1.exe', GENERIC_WRITE, FILE_SHARE_READ, nil, CREATE_NEW, 0, 0);
   HandleStream := THandleStream.Create(hVirtualFile);
   ResourceStream := TResourceStream.Create(0, 'EXE1', 'EXE');
   HandleStream.CopyFrom(ResourceStream, ResourceStream.Size);
   HandleStream.Free;
   ResourceStream.Free;
   CloseHandle(hVirtualFile);

   hVirtualFile:= BoxedAppSDK_CreateVirtualFile('Dll1.dll', GENERIC_WRITE, FILE_SHARE_READ, nil, CREATE_NEW, 0, 0);
   HandleStream := THandleStream.Create(hVirtualFile);
   ResourceStream := TResourceStream.Create(0, 'DLL1', 'DLL');
   HandleStream.CopyFrom(ResourceStream, ResourceStream.Size);
   HandleStream.Free;
   ResourceStream.Free;
   CloseHandle(hVirtualFile);

   hVirtualFile:= BoxedAppSDK_CreateVirtualFile('1.txt', GENERIC_WRITE, FILE_SHARE_READ, nil, CREATE_NEW, 0, 0);
   HandleStream := THandleStream.Create(hVirtualFile);
   ResourceStream := TResourceStream.Create(0, 'TXT1', 'TXT');
   HandleStream.CopyFrom(ResourceStream, ResourceStream.Size);
   HandleStream.Free;
   ResourceStream.Free;
   CloseHandle(hVirtualFile);

   WinExec('1.exe 1.txt', SW_SHOW);

   MessageBox(0, 'Click OK to close main application', 'Information', MB_OK);
end.
