Microsoft XML Core Services (MSXML) 5.0 for Microsoft Office - Digital Signatures

C/C++ Source: DBStream.cpp

The following is the class implementation of DBStream used in the setDebugOutput project.

#include <stdio.h>
#include "DBStream.h"


///////////////////////
// Constructor and destructor:
//
DBStream::DBStream(void) 
{
    _nCount = 1;
   _refcount = 1;
}

DBStream::~DBStream()
{

}

////////////////////////
// IUnknown interface:
//
HRESULT STDMETHODCALLTYPE DBStream::QueryInterface(
   REFIID riid, 
   void ** ppvObject)
{
   if (riid == IID_IUnknown)
    {
        *ppvObject = static_cast<IUnknown*>(this);
    }
    else if (riid == IID_IStream)
    {
        *ppvObject = static_cast<IStream*>(this);
    }
    else
    {
        *ppvObject = NULL;
        return E_NOINTERFACE;
    }
    AddRef();
    return S_OK;
}
    
ULONG STDMETHODCALLTYPE DBStream::AddRef( void)
{
    return InterlockedIncrement(&_refcount);
}
    
ULONG STDMETHODCALLTYPE DBStream::Release( void)
{
    if (InterlockedDecrement(&_refcount) == 0)
    {
        delete this;
        return 0;
    }
   return _refcount;
}

///////////////////////////////////////////////////////////
// IStream Interface:
//
HRESULT STDMETHODCALLTYPE DBStream::Commit(DWORD grfCommitFlags)
{
    _nState = grfCommitFlags;
    switch(_nState)
    {
    case 0:// Start digest computation
      dprintf("\n=== Catching digest %d. ===\n",_nCount);
        break;
    case 1:// End digest computation
      dprintf("=== Digest %d caught.===\n\n", _nCount);
       _nCount++;
        break;
   }

   return S_OK;
}

HRESULT STDMETHODCALLTYPE DBStream::Write(
   void const* pv, 
   ULONG cb, 
   ULONG * pcbWritten)
{
   dprintf("  ===Begin DBStream::Write  (cb=%d)\n", cb);
   dprintf("%s\n", pv);
   dprintf("  ===End DBStream::Write  (cb=%d)\n", cb);
   return S_OK;

}

HRESULT STDMETHODCALLTYPE DBStream::Read(
   void * pv, 
   ULONG cb, 
   ULONG * pcbRead)
{
   return E_NOTIMPL;
}

HRESULT STDMETHODCALLTYPE DBStream::Seek(
   LARGE_INTEGER dlibMove, 
   DWORD dwOrigin, 
   ULARGE_INTEGER * plibNewPosition)
{
    return E_NOTIMPL;
}

HRESULT STDMETHODCALLTYPE DBStream::SetSize(
   ULARGE_INTEGER libNewSize)
{
    return E_NOTIMPL;
}

HRESULT STDMETHODCALLTYPE DBStream::CopyTo(
   IStream * pstm, 
   ULARGE_INTEGER cb,
   ULARGE_INTEGER * pcbRead, 
   ULARGE_INTEGER * pcbWritten)
{
    return E_NOTIMPL;
} 
     
HRESULT STDMETHODCALLTYPE DBStream::Revert(void)
{
    return E_NOTIMPL;
}

HRESULT STDMETHODCALLTYPE DBStream::LockRegion( 
   ULARGE_INTEGER libOffset, 
   ULARGE_INTEGER cb, 
   DWORD dwLockType)
{
    return E_NOTIMPL;
}

HRESULT STDMETHODCALLTYPE DBStream::UnlockRegion(
   ULARGE_INTEGER libOffset, 
   ULARGE_INTEGER cb, 
   DWORD dwLockType)
{
    return E_NOTIMPL;
}

HRESULT STDMETHODCALLTYPE DBStream::Stat(
   STATSTG * pstatstg, 
   DWORD grfStatFlag)
{
    return E_NOTIMPL;
}

HRESULT STDMETHODCALLTYPE DBStream::Clone(
   IStream ** ppstm)
{
    return E_NOTIMPL;
}

// This helper method outputs a message to both stdout and 
// debug-output in Visual Studio.
void STDMETHODCALLTYPE DBStream::dprintf( char * format, ...)
{
    static char buf[1024];
    va_list args;
    va_start( args, format );
    vsprintf( buf, format, args );
    va_end( args);
    OutputDebugStringA( buf);
    printf("%s", buf);
}