storage.cpp
上传用户:bjlvip
上传日期:2010-02-08
资源大小:744k
文件大小:1k
- #define _WIN32_DCOM
- #include <windows.h>
- #include <iostream.h>
- void main(void)
- {
- HRESULT hr;
- CoInitialize(NULL);
- IStorage* pStorage;
- StgCreateDocfile(L"C:\TestFile.STG", STGM_DIRECT|STGM_CREATE|STGM_READWRITE|STGM_SHARE_EXCLUSIVE, 0, &pStorage);
- IPropertySetStorage* pPropertySetStorage;
- pStorage->QueryInterface(IID_IPropertySetStorage, (void**)&pPropertySetStorage);
-
- IPropertyStorage* pPropertyStorage;
- pPropertySetStorage->Create(FMTID_SummaryInformation, NULL, PROPSETFLAG_ANSI, STGM_CREATE|STGM_READWRITE|STGM_SHARE_EXCLUSIVE, &pPropertyStorage);
- PROPSPEC ps;
- ps.ulKind = PRSPEC_PROPID;
- ps.propid = PIDSI_AUTHOR;
- PROPVARIANT pv;
- pv.vt = VT_LPSTR;
- pv.pszVal = "Guy Eddon";
- hr = pPropertyStorage->WriteMultiple(1, &ps, &pv, 0);
- pPropertyStorage->Release();
- pPropertySetStorage->Release();
- IStream* pStream;
- hr = pStorage->CreateStream(L"MyDataStream", STGM_DIRECT|STGM_CREATE|STGM_WRITE|STGM_SHARE_EXCLUSIVE, 0, 0, &pStream);
- ULONG bytes_written;
- char data[] = "HELLO THERE!";
- pStream->Write(data, strlen(data), &bytes_written);
- pStream->Release();
- pStorage->Release();
- CoUninitialize();
- }