Leaked source code of windows server 2003
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.

341 lines
7.9 KiB

  1. #include "pch.cxx"
  2. #include <windows.h>
  3. #include <ole2.h>
  4. #include "PStgServ.h"
  5. #include "PStgServ.hxx"
  6. #include "global.hxx" // PropTest global information
  7. const IID IID_IPropertyStorageServer = {0xaf4ae0d0,0xa37f,0x11cf,{0x8d,0x73,0x00,0xaa,0x00,0x4c,0xd0,0x1a}};
  8. const IID IID_IPropertyStorageServer2= {0xaf4ae0d0,0xa37f,0x11cf,{0x8d,0x73,0x00,0xaa,0x00,0x4c,0xd0,0x1b}};
  9. EnumImplementation g_enumImplementation;
  10. DWORD g_Restrictions;
  11. HINSTANCE g_hinstDLL = NULL;
  12. FNSTGCREATEPROPSTG *g_pfnStgCreatePropStg = NULL;
  13. FNSTGOPENPROPSTG *g_pfnStgOpenPropStg = NULL;
  14. FNSTGCREATEPROPSETSTG *g_pfnStgCreatePropSetStg = NULL;
  15. FNFMTIDTOPROPSTGNAME *g_pfnFmtIdToPropStgName = NULL;
  16. FNPROPSTGNAMETOFMTID *g_pfnPropStgNameToFmtId = NULL;
  17. FNPROPVARIANTCLEAR *g_pfnPropVariantClear = NULL;
  18. FNPROPVARIANTCOPY *g_pfnPropVariantCopy = NULL;
  19. FNFREEPROPVARIANTARRAY *g_pfnFreePropVariantArray = NULL;
  20. STDMETHODIMP
  21. CClassFactory::QueryInterface( REFIID riid, void **ppvObject )
  22. {
  23. IUnknown *pUnk = NULL;
  24. if( riid == IID_IUnknown
  25. ||
  26. riid == IID_IClassFactory
  27. )
  28. {
  29. pUnk = this;
  30. }
  31. if( pUnk != NULL )
  32. {
  33. pUnk->AddRef();
  34. *ppvObject = pUnk;
  35. return S_OK;
  36. }
  37. *ppvObject = NULL;
  38. return E_NOINTERFACE;
  39. }
  40. STDMETHODIMP_(ULONG)
  41. CClassFactory::AddRef( void )
  42. {
  43. return( ++m_cRefs );
  44. }
  45. STDMETHODIMP_(ULONG)
  46. CClassFactory::Release( void )
  47. {
  48. m_cRefs--;
  49. if( m_cRefs == 0 )
  50. {
  51. delete this;
  52. return( 0 );
  53. }
  54. return( m_cRefs );
  55. }
  56. STDMETHODIMP
  57. CClassFactory::CreateInstance( IUnknown *pUnkOuter,
  58. REFIID riid,
  59. void **ppvObject )
  60. {
  61. CPropertyStorageServer *pObj = NULL;
  62. if( pUnkOuter != NULL )
  63. {
  64. return( CLASS_E_NOAGGREGATION );
  65. }
  66. pObj = new CPropertyStorageServer( this );
  67. if( pObj == NULL )
  68. {
  69. return( E_OUTOFMEMORY );
  70. }
  71. return pObj->QueryInterface( riid, ppvObject );
  72. }
  73. STDMETHODIMP
  74. CClassFactory::LockServer( BOOL fLock )
  75. {
  76. if( fLock )
  77. {
  78. m_cLocks++;
  79. }
  80. else
  81. {
  82. m_cLocks--;
  83. }
  84. if( m_cLocks == 0 )
  85. {
  86. PostMessage( m_hWnd, WM_USER, 0, 0 );
  87. }
  88. return S_OK;
  89. }
  90. STDMETHODIMP
  91. CPropertyStorageServer::QueryInterface( REFIID riid, void **ppvObject )
  92. {
  93. *ppvObject = NULL;
  94. IUnknown *pUnk = NULL;
  95. if( riid == IID_IUnknown
  96. ||
  97. riid == IID_IPropertyStorageServer
  98. )
  99. {
  100. pUnk = this;
  101. }
  102. if( pUnk != NULL )
  103. {
  104. pUnk->AddRef();
  105. *ppvObject = pUnk;
  106. return S_OK;
  107. }
  108. *ppvObject = NULL;
  109. return E_NOINTERFACE;
  110. }
  111. STDMETHODIMP_(ULONG)
  112. CPropertyStorageServer::AddRef( void )
  113. {
  114. return( ++m_cRefs );
  115. }
  116. STDMETHODIMP_(ULONG)
  117. CPropertyStorageServer::Release( void )
  118. {
  119. if( --m_cRefs == 0 )
  120. {
  121. delete this;
  122. return( 0 );
  123. }
  124. return( m_cRefs );
  125. }
  126. STDMETHODIMP
  127. CPropertyStorageServer::StgOpenPropStg( const OLECHAR *pwcsName,
  128. REFFMTID fmtid,
  129. DWORD grfMode,
  130. IPropertyStorage **pppstg )
  131. {
  132. HRESULT hr;
  133. IPropertySetStorage *ppsstg = NULL;
  134. if( m_pstg )
  135. {
  136. m_pstg->Release();
  137. m_pstg = NULL;
  138. }
  139. hr = ::StgOpenStorageEx (
  140. pwcsName,
  141. grfMode,
  142. DetermineStgFmt( g_enumImplementation ),
  143. 0,
  144. NULL,
  145. NULL,
  146. PROPIMP_NTFS == g_enumImplementation ? IID_IFlatStorage : IID_IStorage,
  147. (void**) &m_pstg );
  148. if( FAILED(hr) ) goto Exit;
  149. hr = m_pstg->QueryInterface( IID_IPropertySetStorage, (void**) &ppsstg );
  150. if( FAILED(hr) ) goto Exit;
  151. hr = ppsstg->Open( fmtid, grfMode, pppstg );
  152. if( FAILED(hr) ) goto Exit;
  153. Exit:
  154. if( FAILED(hr)
  155. &&
  156. m_pstg != NULL )
  157. {
  158. m_pstg->Release();
  159. m_pstg = NULL;
  160. }
  161. if( ppsstg ) ppsstg->Release();
  162. return( hr );
  163. }
  164. STDMETHODIMP
  165. CPropertyStorageServer::StgOpenPropSetStg(
  166. const OLECHAR *pwcsName,
  167. DWORD grfMode,
  168. IPropertySetStorage **pppsstg )
  169. {
  170. HRESULT hr;
  171. if( m_pstg )
  172. {
  173. m_pstg->Release();
  174. m_pstg = NULL;
  175. }
  176. hr = ::StgOpenStorageEx (
  177. pwcsName,
  178. grfMode,
  179. DetermineStgFmt( g_enumImplementation ),
  180. 0,
  181. NULL,
  182. NULL,
  183. PROPIMP_NTFS == g_enumImplementation ? IID_IFlatStorage : IID_IStorage,
  184. (void**) &m_pstg );
  185. if( FAILED(hr) ) goto Exit;
  186. hr = m_pstg->QueryInterface( IID_IPropertySetStorage, (void**) pppsstg );
  187. if( FAILED(hr) ) goto Exit;
  188. Exit:
  189. if( FAILED(hr)
  190. &&
  191. m_pstg != NULL )
  192. {
  193. m_pstg->Release();
  194. m_pstg = NULL;
  195. }
  196. return( hr );
  197. }
  198. STDMETHODIMP
  199. CPropertyStorageServer::MarshalUnknown( IUnknown *punk )
  200. {
  201. punk->AddRef();
  202. punk->Release();
  203. return( S_OK );
  204. }
  205. STDMETHODIMP
  206. CPropertyStorageServer::Initialize( EnumImplementation enumImplementation,
  207. ULONG Restrictions )
  208. {
  209. HRESULT hr;
  210. g_enumImplementation = enumImplementation;
  211. g_Restrictions = Restrictions;
  212. if( PROPIMP_DOCFILE_IPROP == g_enumImplementation )
  213. {
  214. // We're to use the propset APIs from IProp
  215. g_hinstDLL = LoadLibraryA( "iprop.dll" );
  216. }
  217. else
  218. {
  219. // We're to use the propset APIs from OLE32
  220. g_hinstDLL = LoadLibraryA( "ole32.dll" );
  221. }
  222. if( NULL == g_hinstDLL )
  223. {
  224. hr = ERROR_MOD_NOT_FOUND;
  225. goto Exit;
  226. }
  227. // Get pointers to the functions that we always use
  228. // (e.g., PropVariantCopy, but not StgCreatePropSetStg)
  229. hr = ERROR_PROC_NOT_FOUND;
  230. g_pfnPropVariantCopy = (FNPROPVARIANTCOPY*)
  231. GetProcAddress( g_hinstDLL,
  232. "PropVariantCopy" );
  233. if( NULL == g_pfnPropVariantCopy ) goto Exit;
  234. g_pfnPropVariantClear = (FNPROPVARIANTCLEAR*)
  235. GetProcAddress( g_hinstDLL,
  236. "PropVariantClear" );
  237. if( NULL == g_pfnPropVariantClear ) goto Exit;
  238. g_pfnFreePropVariantArray = (FNFREEPROPVARIANTARRAY*)
  239. GetProcAddress( g_hinstDLL,
  240. "FreePropVariantArray" );
  241. if( NULL == g_pfnFreePropVariantArray ) goto Exit;
  242. g_pfnStgCreatePropSetStg = (FNSTGCREATEPROPSETSTG*)
  243. GetProcAddress( g_hinstDLL,
  244. "StgCreatePropSetStg" );
  245. if( NULL == g_pfnStgCreatePropSetStg ) goto Exit;
  246. g_pfnStgCreatePropStg = (FNSTGCREATEPROPSTG*)
  247. GetProcAddress( g_hinstDLL,
  248. "StgCreatePropStg" );
  249. if( NULL == g_pfnStgCreatePropStg ) goto Exit;
  250. g_pfnStgOpenPropStg = (FNSTGOPENPROPSTG*)
  251. GetProcAddress( g_hinstDLL,
  252. "StgOpenPropStg" );
  253. if( NULL == g_pfnStgOpenPropStg ) goto Exit;
  254. g_pfnFmtIdToPropStgName = (FNFMTIDTOPROPSTGNAME*)
  255. GetProcAddress( g_hinstDLL,
  256. "FmtIdToPropStgName" );
  257. if( NULL == g_pfnFmtIdToPropStgName ) goto Exit;
  258. g_pfnPropStgNameToFmtId = (FNPROPSTGNAMETOFMTID*)
  259. GetProcAddress( g_hinstDLL,
  260. "PropStgNameToFmtId" );
  261. if( NULL == g_pfnPropStgNameToFmtId ) goto Exit;
  262. hr = S_OK;
  263. Exit:
  264. return( hr );
  265. }