///////////////////////////////////////////////////////////// // strdStrg.cpp - create storage // // // // Jim Fawcett, CSE775 - Distributed Objects, Spring 2005 // ///////////////////////////////////////////////////////////// #include #include #include using namespace std; void main(void) { cout << "\n Demonstrate Basic Structured Storage - writing" << "\n ================================================\n"; HRESULT hr; CoInitialize(NULL); cout << "\n create a structured storage file containing a root storage\n"; IStorage* pStorage; StgCreateDocfile( L"c:\\temp\\NewTestFile.STG", STGM_DIRECT|STGM_CREATE|STGM_READWRITE|STGM_SHARE_EXCLUSIVE, 0, &pStorage ); cout << "\n create a stream in root storage"; IStream *pStream1, *pStream2; hr = pStorage-> CreateStream( L"firstStream", STGM_DIRECT|STGM_CREATE|STGM_WRITE|STGM_SHARE_EXCLUSIVE, 0, 0, &pStream1 ); cout << "\n write the string \"In First Stream!\" into the stream\n"; ULONG bytes_written; char data1[] = "In First Stream!"; pStream1->Write(data1, strlen(data1), &bytes_written); cout << "\n create a second stream in root storage"; hr = pStorage-> CreateStream( L"secondStream", STGM_DIRECT|STGM_CREATE|STGM_WRITE|STGM_SHARE_EXCLUSIVE, 0, 0, &pStream2 ); cout << "\n write the string \"In Second Stream!\" into the second stream\n"; char data2[] = "In Second Stream!"; pStream2->Write(data2, strlen(data2), &bytes_written); cout << "\n release both streams and storage\n\n"; pStream1->Release(); pStream2->Release(); pStorage->Release(); CoUninitialize(); }