/*
*********************************************************************
*
*	The Essence of OLE
*
*	Source code sample
*
*	Copyright (c) 1996, Rolling Thunder Computing, Ipswich MA
*
*	e-mail: essence@rollthunder.com
*	CompuServe: 73540.3430
*	Web: http://www.rollthunder.com
*
*	File Name: STGUTIL.CPP
*
*	Purpose: Utility functions for structured storage app
*
*********************************************************************
*/


#include <windows.h>
#include "main.h"



extern CLSID MyCLSID ;
extern HWND hEdit ;

BOOL WriteNewStorageStructure (LPSTORAGE pNewStg) 
{

/*
STEP 2
Write our class ID into the storage so we can identify it
*/



/*
STEP 2
Create a stream for data in DisplayText[], then release it because we don't need it 
here any more.
*/


	
/*
STEP 2
Create new substorage for summary info.
*/

/*
STEP 2
Create new title and author streams in the Summary Info substorage, write default
data into them, then release both streams and substorage.
*/

	return TRUE ;
}	



BOOL OpenFileByName (OLECHAR *pName, LPSTORAGE *ppStgOut)
{

	LPSTORAGE pNewStg ;
	LPSTREAM pStream ;


/*
STEP 4
Check to see if this is a compound storage file.  If not, complain and quit.
*/
	if (1/* perform check here*/ )
	{
		MessageBox (NULL, "File is not a structured storage file",
			"Error", MB_OK | MB_ICONSTOP) ;
		return FALSE ;
	}
	

/*
STEP 4
It is a structured storage file; open it. If unable to, 
the complain and quit.
*/



	char AnsiName [256] ;
	WideCharToMultiByte (CP_ACP, 0, pName, -1, AnsiName, sizeof (AnsiName), NULL, NULL) ;

	if (!pNewStg)
	{
		MessageBox (NULL, AnsiName, "Couldn't open file", MB_OK | MB_ICONSTOP) ;
		return FALSE ;
	}

/*
STEP 4
Check to see if the root storage's class ID is the one we gave it, i.e. it's one 
of our files.  If not, complain and quit.
*/

	if (1 /* perform check here*/ )
	{
		MessageBox (NULL, "File's class ID is different from ours",
			"Error", MB_OK | MB_ICONSTOP) ;

		pNewStg->Release ( ) ;
		return FALSE ;
	}


/*
It's our file, all right.  Open stream that contains text data, read it in,
and release the stream
*/

	char buf [4096] ;
	
	pNewStg->OpenStream (L"DisplayText",  NULL, 
		STGM_READ | STGM_SHARE_EXCLUSIVE, NULL,
		&pStream) ;

	pStream->Read (buf, sizeof(buf), NULL) ;
	pStream->Release( ) ;

	SetWindowText (hEdit, buf) ;

	*ppStgOut = pNewStg ;

	return TRUE ;
}
