Newsgroups : Borland : borland.public.delphi.nativeapi.win32 : 2007 Aug : Save IStorage to a file

www.cryer.info
Managed Newsgroup Archive

Save IStorage to a file

Subject:Save IStorage to a file
Posted by:"bilm" (fence617..@mypacks.net)
Date:Fri, 10 Aug 2007 13:45:31

I need to save the contents of an IStorage to a file on the HD.
Will this function do it ? Is there a better/easier way ?

function SaveIStorageToFile(const Stor: IStorage; FileName: String):
HResult;
var stgStream: IStream;
    OleStream: TOleStream;
    mStream : TMemoryStream;
begin

  OleCheck(Stor.CreateStream(nil, STGM_CREATE or
                             STGM_READWRITE or
                             STGM_DIRECT or
                             STGM_SHARE_EXCLUSIVE,
                             0, 0, stgStream));

  OleStream := TOleStream.Create( stgStream );
  mStream := TMemoryStream.Create;

  try
    mStream.CopyFrom(OleStream, OleStream.Size);
    mStream.SaveToFile(FileName);

  finally
    FreeAndNil(OleStream);
    FreeAndNil(mStream);
  end;
  Result := S_OK;
end;

bilm

Replies:

www.cryer.info
Managed Newsgroup Archive