Composite document operation-read/write struct

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.