[python-win32] how to generate an IPersistStream object?

Mark Hammond mhammond at skippinet.com.au
Tue Jan 30 04:32:57 CET 2007


> On 1/30/07, Mark Hammond <mhammond at skippinet.com.au> wrote:
> > > i need to pass an IPersistStream object to a COM function,
> > > and i find a type named PyIPersistStream in the manual of pywin32.
> > >
> > > but i don't know how to generate a PyIPersistStream
> object and pass it
> > > to the function.
> > > anyone could help me?
> >
> > Gabriel is completely correct - see
> ./win32com/demos/ietoolbar.py and
> > ./win32com/test/testStreams.py for 2 samples that use this
> interface.
> >
>
> thanks to all of you for helping me.
>
> do i have to implement the IPersistStream by my self?
> regarding to IStorage and IStream, i can invoke StgCreateDocfile and
> IStorage::CreateStream to generate corresponding objects.
>
> i thought there must be some way to do that effectively, without
> having to do all trivial things by myself.

That is the nature of interfaces - they generally don't come with an
implementation.  Certainly Python removes the need for many of the trivial
things C++ would require you to do, but I can't think of any other details a
generic Python implementation could provide.  However, if you can come up
with an implementation of a base class you believe would be useful for
people implementing this interface I'd be happy to look at including it in
pywin32.

>
> i went through all of the samples coming up with pywin32 before i post
> this thread.
> as to ./win32com/test/testStreams.py, it implements IStream and
> IPersist interfaces
> by itself (and the implementation is incomplete).
> i don't think that's a good way to implement all of the interfaces
> that i need, do you?

It obviously depends on your caller - but in general I agree, providing a
partial implementation of an interface is not what production code should
do.  But that is the nature of samples - they are intended to give you
enough information to create something for your own application and do not
profess to be complete implementations of anything.

Mark



More information about the Python-win32 mailing list