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.

190 lines
3.9 KiB

  1. // StorageFactory.cpp : Implementation of CDelme2App and DLL registration.
  2. #include "stdafx.h"
  3. #include "StorageFactory.h"
  4. HRESULT STDMETHODCALLTYPE SetIStorage(
  5. IN IStorage *pIStorage,
  6. IN const EnStorageMode enStorageMode,
  7. OUT ITStorage **ppStorage)
  8. {
  9. LOG((MSP_TRACE, "CTStorageFactory::SetIStorage - enter"));
  10. LOG((MSP_TRACE, "CTStorageFactory::SetIStorage - completed"));
  11. return E_NOTIMPL;
  12. }
  13. HRESULT OpenStorage(
  14. IN const OLECHAR *pwcsStorageName,
  15. EnStorageMode enStorageMode,
  16. OUT ITStorage **ppStorage)
  17. {
  18. LOG((MSP_TRACE, "CTStorageFactory::OpenStorage - enter"));
  19. //
  20. // check arguments
  21. //
  22. if (IsBadWritePtr(ppStorage, sizeof(ITStorage*)))
  23. {
  24. LOG((MSP_ERROR, "CTStorageFactory::OpenStorage - bad pointer passed in ppStorage %p", ppStorage));
  25. return E_POINTER;
  26. }
  27. //
  28. // don't return garbage if we fail
  29. //
  30. *ppStorage = NULL;
  31. if (IsBadStringPtr(pwcsStorageName, -1))
  32. {
  33. LOG((MSP_ERROR, "CTStorageFactory::PrepareStorage - bad pointer passed in pwcsStorageName %p", pwcsStorageName));
  34. return E_POINTER;
  35. }
  36. LOG((MSP_TRACE, "CTStorageFactory::OpenStorage - opening [%S] in mode [%x]", pwcsStorageName, enStorageMode));
  37. //
  38. // get file extension
  39. //
  40. OLECHAR *pszExtention = wcsrchr(pwcsStorageName, '.');
  41. //
  42. // make sure file has extension
  43. //
  44. if (NULL == pszExtention)
  45. {
  46. LOG((MSP_ERROR, "CTStorageFactory::OpenStorage - file name %S does not have extentsion", pwcsStorageName));
  47. return TAPI_E_NOTSUPPORTED;
  48. }
  49. //
  50. // extension follows the dot.
  51. //
  52. pszExtention++;
  53. //
  54. // (pszExtention is still valid -- if the dot was at the end,
  55. // we now point to \0)
  56. //
  57. CLSID clsID;
  58. //
  59. // check extention. we currently only support AVI and wav
  60. // make this logic more flexible if we want to support asf, wma, wmv)
  61. //
  62. if (0 == _wcsicmp(pszExtention, L"avi"))
  63. {
  64. LOG((MSP_TRACE, "CTStorageFactory::OpenStorage - creating avi storage unit"));
  65. //
  66. // create avi storage
  67. //
  68. clsID = CLSID_TStorageUnitAVI;
  69. }
  70. else if (0 == _wcsicmp(pszExtention, L"wav"))
  71. {
  72. LOG((MSP_TRACE, "CTStorageFactory::OpenStorage - creating wav storage unit"));
  73. //
  74. // create wav storage
  75. //
  76. clsID = CLSID_TStorageUnitAVI;
  77. }
  78. else
  79. {
  80. //
  81. // failed to recognize file type
  82. //
  83. LOG((MSP_ERROR, "CTStorageFactory::OpenStorage - unrecognized file type"));
  84. return TAPI_E_NOTSUPPORTED;
  85. }
  86. //
  87. // we know the storage unit class id. attemt to create it
  88. //
  89. ITStorage *pStorageUnit = NULL;
  90. HRESULT hr = CoCreateInstance(clsID,
  91. NULL,
  92. CLSCTX_ALL,
  93. IID_ITStorage,
  94. (void**)&pStorageUnit
  95. );
  96. if (FAILED(hr))
  97. {
  98. LOG((MSP_ERROR, "CTStorageFactory::OpenStorage - failed to instantiate storage unit"));
  99. return hr;
  100. }
  101. //
  102. // configure storage unit with file name
  103. //
  104. hr = pStorageUnit->Initialize(pwcsStorageName, enStorageMode);
  105. //
  106. // if failed, cleanup and bail out
  107. //
  108. if (FAILED(hr))
  109. {
  110. LOG((MSP_ERROR, "CTStorageFactory::OpenStorage - failed to initialize storage unit, hr = %lx", hr));
  111. pStorageUnit->Release();
  112. return hr;
  113. }
  114. //
  115. // everything went well -- return ITStorage interface of the storage unit
  116. // we have just created
  117. //
  118. *ppStorage = pStorageUnit;
  119. LOG((MSP_TRACE, "CTStorageFactory::OpenStorage - exit. returning storage unit %p", *ppStorage));
  120. return S_OK;
  121. }