Solved

How to implement my own IStream derived object

Posted on 2004-04-19
5
1,436 Views
Last Modified: 2012-05-04
Hi,
I want to implement a class derived from the IStream interface?
I want this to be used as the stream of an IStorage object .

Possible?

cheers
-Roman
0
Comment
Question by:romanm
  • 3
5 Comments
 
LVL 1

Expert Comment

by:Bird__
ID: 10864888
do you mean istream? (not capital IStream)

if so, then check out this site.
it's a good (and the only one i can find online) guide to how the iostream works, and how to derive a class from it
http://spec.winprog.org/streams/
0
 
LVL 3

Author Comment

by:romanm
ID: 10865125
No, IStream an interface used by structured storage.
0
 
LVL 9

Accepted Solution

by:
_ys_ earned 125 total points
ID: 10871576
Of course it's possible. Albeit quite a bit of work.

You need to:
- [obviously] create your component and implement IStorage.
- roll out your own IMoniker implementation (typically on your class factory)
- implement IMoniker::BindToStorage to specifically return your custom IStorage implementation

Of course, anyone using your component would then have know how to use monikers properly in order to create your component.

Implementations of IMoniker and IStorate et al. are non-trivial. What's wrong with the default implementation? You just playing around?

I presented a write up on monikers before, although you need to know the basics well to read it:
http://www.experts-exchange.com/Programming/Programming_Languages/Cplusplus/Q_20775283.html
0
 
LVL 3

Author Comment

by:romanm
ID: 10871926
What I am trying to do is to make a source/write filter for msxml,
I want to create an encrypted form of a file that I could use as a source file for SAX parsing.
0
 
LVL 3

Author Comment

by:romanm
ID: 10872853
// I have found a simple solution to my problem:

class CMyXMLSourceFilter : public CUnknown, public ISequentialStream
{
public:
      long __stdcall Read(void* pv, unsigned long cb, unsigned long* pcbRead);
      long __stdcall Write(const void* pv, unsigned long cb, unsigned long* pcbRead);
      static HRESULT CreateInstance(IUnknown * pUnknownOuter, CUnknown ** ppNewComponent);
      
      DECLARE_IUNKNOWN      // IUnknown

      void open(bool b);
            
protected:
      CMyXMLSourceFilter(IUnknown* pUnknpwnOuter);
      virtual ~CMyXMLSourceFilter() {};
      
private:
      FILE*      f;
      
      // INondelegatingUnknown
      virtual HRESULT __stdcall  NondelegatingQueryInterface( const IID& iid, void ** ppv);
      virtual void FinalRelease();
};

CMyXMLSourceFilter::CMyXMLSourceFilter(IUnknown* pUnknpwnOuter) : CUnknown(pUnknpwnOuter)
{
}

void CMyXMLSourceFilter::open(bool b)
{
      if( b )
            f = fopen("C:\\test.stg", "wb" );
      else
            f = fopen("C:\\test.stg", "rb" );
}

HRESULT CMyXMLSourceFilter::CreateInstance(IUnknown * pUnknownOuter, CUnknown ** ppNewComponent)
{
      *ppNewComponent = new CMyXMLSourceFilter(pUnknownOuter);

      return S_OK;
}

// INondelegatingUnknown
HRESULT CMyXMLSourceFilter::NondelegatingQueryInterface( const IID& iid, void ** ppv)
{
      if(iid == __uuidof(ISequentialStream))
      {
            return FinishQI(static_cast<ISequentialStream*>(this),ppv);
      }
      else
      {
            return CUnknown::NondelegatingQueryInterface(iid,ppv);
      }
}

void CMyXMLSourceFilter::FinalRelease()
{
      fclose(f);
}

long CMyXMLSourceFilter::Read(void* pv, unsigned long cb, unsigned long* pcbRead)
{
      size_t l = fread(pv, 1, cb, f);
      if( pcbRead != NULL )
            *pcbRead = l;
      return 0;
}
long CMyXMLSourceFilter::Write(const void* pv, unsigned long cb, unsigned long* pcbRead)
{
      size_t l = fwrite(pv, 1, cb, f);
      if( pcbRead != NULL )
            *pcbRead = l;
      return 0;
}

//
// And the usage:
//

      ISAXXMLReaderPtr pSax;
      pSax.CreateInstance(CLSID_SAXXMLReader30);
      CMyXMLSourceFilter* cc1;
      CMyXMLSourceFilter::CreateInstance(NULL, (CUnknown**)&cc1);
      cc1->open(false);
      pcc.Attach(cc1,false);
      _variant_t var1(pcc);
      pSax->parse(var1);
      pcc = NULL;


I'll award the points for effort ;)
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question