storage.cpp
上传用户:bjlvip
上传日期:2010-02-08
资源大小:744k
文件大小:1k
源码类别:

Windows编程

开发平台:

Visual C++

  1. #define _WIN32_DCOM
  2. #include <windows.h>
  3. #include <iostream.h>
  4. void main(void)
  5. {
  6. HRESULT hr;
  7. CoInitialize(NULL);
  8. IStorage* pStorage;
  9. StgCreateDocfile(L"C:\TestFile.STG", STGM_DIRECT|STGM_CREATE|STGM_READWRITE|STGM_SHARE_EXCLUSIVE, 0, &pStorage);
  10. IPropertySetStorage* pPropertySetStorage;
  11. pStorage->QueryInterface(IID_IPropertySetStorage, (void**)&pPropertySetStorage);
  12. IPropertyStorage* pPropertyStorage;
  13. pPropertySetStorage->Create(FMTID_SummaryInformation, NULL, PROPSETFLAG_ANSI, STGM_CREATE|STGM_READWRITE|STGM_SHARE_EXCLUSIVE, &pPropertyStorage);
  14. PROPSPEC ps;
  15. ps.ulKind = PRSPEC_PROPID;
  16. ps.propid = PIDSI_AUTHOR;
  17. PROPVARIANT pv;
  18. pv.vt = VT_LPSTR;
  19. pv.pszVal = "Guy Eddon";
  20. hr = pPropertyStorage->WriteMultiple(1, &ps, &pv, 0);
  21. pPropertyStorage->Release();
  22. pPropertySetStorage->Release();
  23. IStream* pStream;
  24. hr = pStorage->CreateStream(L"MyDataStream", STGM_DIRECT|STGM_CREATE|STGM_WRITE|STGM_SHARE_EXCLUSIVE, 0, 0, &pStream);
  25. ULONG bytes_written;
  26. char data[] = "HELLO THERE!";
  27. pStream->Write(data, strlen(data), &bytes_written);
  28. pStream->Release();
  29. pStorage->Release();
  30. CoUninitialize();
  31. }