Re: Copy an IStorage interface to an IStream interface for ATTACH_OLE attachments




"Dmitry Streblechenko" <dmitry@xxxxxxxxxxx> wrote in message news:uQCAWcViIHA.1168@xxxxxxxxxxxxxxxxxxxxxxx
IID_IStreamDocfile shoudl do the job if all you want to do is persist the data in a stream.

I appreciate the help...
For this particular attachment (Rich Text email with embedded Bitmap image) I get E_NOINTERFACE.

Thus I try IID_IStorage. Now I want to just stream that to memory. I am trying to implment the
function CreateMemoryStreamFromIStorage shown in the link below and it appears to copy to memory
but I am just not sure if everything is correct or even how to tell at this point. It will be months away
before I care about loading these attachments back into Outlook. For the moment I just want to
stream them out...




http://delphi.newswhat.com/geoxml/forumhistorythread?groupname=borland.public.delphi.oleautomation&messageid=m40ybqr2h8ft$.13ti65ihi7quw.dlg@xxxxxxxxxx

----------------
function CreateMemoryStreamFromIStorage(const Storage: IStorage):
TMemoryStream;
var
LockBytes: ILockBytes;
HGlob: HGLOBAL;
NewStorage: IStorage;
intfStream : IStream;
begin
HGlob := GlobalAlloc(GMEM_MOVEABLE, 0);
try
// TODO : Check if the above memory is leaked.
OleCheck(CreateILockBytesOnHGlobal(HGlob, False, LockBytes));
OleCheck(StgCreateDocfileOnILockBytes(LockBytes,
STGM_CREATE or STGM_READWRITE or STGM_SHARE_EXCLUSIVE{ or
STGM_DIRECT},
0, NewStorage));
OleCheck(Storage.CopyTo(0, nil, nil, NewStorage));
OleCheck(CreateStreamOnHGlobal(HGlob, True, intfStream));
result := StreamFromIStream(intfStream);
result.Seek(0,0);
intfStream := nil;
except
GlobalFree(HGlob);
raise;
end;
end;
--------------------------------


.



Relevant Pages

  • Re: newbie: deactivate query before freeing?
    ... However, to make sure that the memory gets freed, you would have to ... call Free before you assign nil. ... Use Free to destroy an object. ... if the object reference is not nil. ...
    (comp.lang.pascal.delphi.misc)
  • Re: Strange EAccessViolation which I cannot figure out...
    ... Constructors are documented to always set their objects' fields to zero, nil, empty, or unassigned. ... that you should not assume the class to Nil your fields for you automatically in the constructor. ... When memory is allocated, Delphi likes to zero it out, in this case ...
    (comp.lang.pascal.delphi.misc)
  • Re: [9fans] segfree() - more details?
    ... I think russ has added this functionality to his kernel. ... return nil; ... process memory segments - NSEG always last! ... So you would need separate memory segments in between too. ...
    (comp.os.plan9)
  • Re: heavy loop functions slow
    ... set arrayOut to nil if you don't need it any more. ... set it to nil to allow for garbage collection ... dataArray << push ... the long string in memory. ...
    (comp.lang.ruby)
  • [opensuse] jedit failing on openSUSE 11.0
    ... I am unable to run jedit on openSUSE 11.0. ... GC Warning: Out of Memory! ... Returning NIL! ...
    (SuSE)