Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

182 lines
4.5 KiB

  1. // TestStg.cpp -- A simple text program for the IITStorage interface wrapper.
  2. #include <Windows.h>
  3. #include <malloc.h>
  4. #include <stdio.h>
  5. #include <wchar.h>
  6. #include <objbase.h>
  7. #include <urlmon.h>
  8. #include "MSITSTG.h"
  9. typedef IUnknown *PIUnknown;
  10. #define ReleaseObjPtr(pObj) \
  11. { \
  12. if (pObj) \
  13. { \
  14. IUnknown *pUnk= pObj; \
  15. pObj= NULL; \
  16. pUnk->Release(); \
  17. } \
  18. }
  19. #define StorageName L".\\test.df"
  20. const char aItemTypes[] = "?\\:#@!";
  21. // ITControlData defines the current structure of the control data
  22. // used by ITS at the moment. Don't count on it being correct forever.
  23. // Instead you should use IITStorage::EditControlData to set up control
  24. // data. [Real soon now...]
  25. typedef struct _ITControlData
  26. {
  27. UINT cdwFollowing;
  28. DWORD cdwITFS_Control;
  29. DWORD dwMagicITS;
  30. DWORD dwVersionITS;
  31. DWORD cbDirectoryBlock;
  32. DWORD cMinCacheEntries;
  33. DWORD fFlags;
  34. UINT cdwLZXData;
  35. DWORD dwLZXMagic;
  36. DWORD dwVersionLZX;
  37. DWORD cbResetBlock;
  38. DWORD cbWindowSize;
  39. DWORD cbSecondPartition;
  40. DWORD cbExeOpt;
  41. } ITControlData, *PITControlData;
  42. #define Buff_Cnt (200)
  43. void main(int cArgs, char **ppchArgs)
  44. {
  45. #define SHUTDOWN { DebugBreak(); goto shutdown; }
  46. #define BAILOUT { DebugBreak(); goto bail_out; }
  47. IITStorage *pITStorage = NULL;
  48. IStorage *pStorage = NULL;
  49. IStorage *rgpstg[100];
  50. IStream *pstm = NULL;
  51. WCHAR StmName[1024];
  52. WCHAR StgName[1024];
  53. int i,j;
  54. ULONG ulData[Buff_Cnt];
  55. ULONG iData;
  56. ULONG cbWritten= 0;
  57. ULONG ulDataRead[Buff_Cnt];
  58. ULONG cbRead = 0;
  59. WCHAR suffix[10];
  60. ITControlData itcd;
  61. PITControlData pitcd = &itcd;
  62. itcd.cdwFollowing = 13;
  63. itcd.cdwITFS_Control = 5;
  64. itcd.dwMagicITS = 'I' | ('T' << 8) | ('S' << 16) | ('C' << 24);
  65. itcd.dwVersionITS = 1;
  66. itcd.cbDirectoryBlock = 512;
  67. itcd.cMinCacheEntries = 20;
  68. itcd.fFlags = 0x00000000; // Make compression the default.
  69. itcd.cdwLZXData = 6;
  70. itcd.dwLZXMagic = 'L' | ('Z' << 8 ) | ('X' << 16) | ('C' << 24);
  71. itcd.dwVersionLZX = 2;
  72. itcd.cbResetBlock = 2;//32*1024; // 0x40000;
  73. itcd.cbWindowSize = 2;//28*1024; //0x20000;
  74. itcd.cbSecondPartition = 1;//64*1024; //0x10000;
  75. itcd.cbExeOpt = FALSE;
  76. if (!SUCCEEDED(CoInitialize(NULL)))
  77. return;
  78. IClassFactory *pICFITStorage = NULL;
  79. HRESULT hr= CoGetClassObject(CLSID_ITStorage, CLSCTX_INPROC_SERVER, NULL,
  80. IID_IClassFactory, (VOID **)&pICFITStorage
  81. );
  82. if (!SUCCEEDED(hr))
  83. SHUTDOWN
  84. hr= pICFITStorage->CreateInstance(NULL, IID_ITStorage,
  85. (VOID **)&pITStorage
  86. );
  87. ReleaseObjPtr(pICFITStorage);
  88. if (!SUCCEEDED(hr))
  89. SHUTDOWN
  90. hr = pITStorage->EditControlData((PITS_Control_Data *)&pitcd, 0);
  91. hr = pITStorage->SetControlData(PITS_Control_Data(&itcd));
  92. hr= pITStorage->StgCreateDocfile(StorageName,
  93. STGM_READWRITE | STGM_SHARE_EXCLUSIVE
  94. | STGM_DIRECT
  95. | STGM_CREATE,
  96. 0, &pStorage
  97. );
  98. if (!SUCCEEDED(hr))
  99. BAILOUT
  100. for (iData= Buff_Cnt; iData--; )
  101. ulData[iData] = iData;
  102. for (i = 0; SUCCEEDED(hr) && (i < 100); i++)
  103. {
  104. _itow(i, suffix, 10);
  105. wcscpy(StgName, L"stg");
  106. wcscat(StgName, suffix);
  107. hr= pStorage->CreateStorage(StgName, STGM_READWRITE, 0, 0, &rgpstg[i]);
  108. for (j = 0; SUCCEEDED(hr) && (j < 100); j++)
  109. {
  110. _itow(j, suffix, 10);
  111. wcscpy(StmName, L"stm");
  112. wcscat(StmName, suffix);
  113. hr= rgpstg[i]->CreateStream(StmName, STGM_READWRITE, 0, 0, &pstm);
  114. hr= pstm->Write(ulData, Buff_Cnt * sizeof(ULONG), &cbWritten);
  115. pstm->Release();
  116. }
  117. }
  118. for (i = 0; SUCCEEDED(hr) && (i < 100); i++)
  119. {
  120. for (j = 0; SUCCEEDED(hr) && (j < 100); j++)
  121. {
  122. _itow(j, suffix, 10);
  123. wcscpy(StmName, L"stm");
  124. wcscat(StmName, suffix);
  125. hr= rgpstg[i]->OpenStream(StmName, 0, STGM_WRITE, 0, &pstm);
  126. hr= pstm->Write(ulData, Buff_Cnt * sizeof(ULONG), &cbWritten);
  127. pstm->Release();
  128. }
  129. ReleaseObjPtr(rgpstg[i]);
  130. }
  131. printf("Everything worked!\n");
  132. bail_out:
  133. ReleaseObjPtr(pStorage);
  134. ReleaseObjPtr(pITStorage);
  135. ReleaseObjPtr(pICFITStorage);
  136. shutdown:
  137. CoUninitialize();
  138. }