Storage Structure
:
# Include "stdafx. H"
# Include <objbase. H.>
# Define result_ OK (HR) if (! Succeeded (HR) goto exit0;
# Define release_interface (x) if (x) {(x)-> release (); (x) = NULL ;}
Class tempdata
{
Public:
Char data [256];
Int count;
} * P;
Int _ tmain (INT argc, _ tchar * argv [])
{
Istorage * pistr = NULL;
Istorage * pisubstr = NULL;
Hresult hR = e_fail;
Istream * pistream = NULL;
Ulong ulsize = 0;
Tchar szbuf [] = _ T ("0123456789 ");
Const tchar * pszfilename = _ T ("C: // test. MCB ");
Tempdata data;
Char temp [] = "1234567890 ";
Data. Count = strlen (temp );
Strcpy (data. Data, temp );
P = & data;
HR = coinitialize (null );
Result_ OK (HR );
// Create a composite document
HR = stgcreatedocfile (pszfilename, stgm_direct | stgm_create | stgm_readwrite | stgm_clu_exclusive, null, & pistr );
Result_ OK (HR );
// Create a data stream
HR = pistr-> createstream (_ T ("mcbstream"), stgm_direct | stgm_create | stgm_readwrite | stgm_clu_exclusive, 0, 0, & pistream );
Result_ OK (HR );
// Write data
// HR = pistream-> write (szbuf, _ tcslen (szbuf) * sizeof (tchar), & ulsize );
HR = pistream-> write (p, sizeof (tempdata), & ulsize );
Result_ OK (HR );
Exit0:
// Release_interface (pistream );
Release_interface (pisubstr );
Release_interface (pistr );
Couninitialize ();
Return 0;
}
Read struct
:
# Include "stdafx. H"
# Include <objbase. H.>
# Define result_ OK (HR) if (! Succeeded (HR) goto exit0;
# Define release_interface (x) if (x) {(x)-> release (); (x) = NULL ;}
Class tempdata
{
Public:
Char data [256];
Int count;
} * P;
Int _ tmain (INT argc, _ tchar * argv [])
{
Istorage * pistr = NULL;
Hresult hR = e_fail;
Istream * pistream = NULL;
Ulong ulsize = 0;
Const tchar * pszfilename = _ T ("C: // test. MCB ");
HR = coinitialize (null );
Result_ OK (HR );
// Create a composite document
HR = stgopenstorage (pszfilename, null, stgm_direct | stgm_readwrite | stgm_clu_exclusive, null, null, & pistr );
Result_ OK (HR );
HR = pistr-> openstream (_ T ("mcbstream"), null, stgm_direct | stgm_readwrite | stgm_clu_exclusive, null, & pistream );
Tempdata data;
P = & data;
HR = pistream-> Read (p, sizeof (tempdata), & ulsize );
Messageboxa (0, P-> data, 0, 0 );
Exit0:
Release_interface (pistream );
Release_interface (pistr );
Return 0;
}
Environment: WINXP (SP3) + IE8
IDE: vs2005