Solved

How to implement my own IStream derived object

Posted on 2004-04-19
5
1,430 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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.

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now