Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to implement my own IStream derived object

Posted on 2004-04-19
5
Medium Priority
?
1,449 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 375 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
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 technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

715 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