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.

120 lines
2.8 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995.
  5. //
  6. // File: STGAPI.CXX
  7. //
  8. // Contents:
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // History: 12-15-95 JoeS (Joe Souza) Created
  15. //
  16. //----------------------------------------------------------------------------
  17. #include <urlint.h>
  18. #include <urlmon.hxx>
  19. #include "clockbyt.hxx"
  20. #include "casynclb.hxx"
  21. #include "filelb.hxx"
  22. #include "memlb.hxx"
  23. #include "stgapi.hxx"
  24. HRESULT StgGetFillLockByteOnMem(IFillLockBytes **pFLB)
  25. {
  26. DEBUG_ENTER_API((DBG_API,
  27. Hresult,
  28. "StgGetFillLockByteOnMem",
  29. "%#x",
  30. pFLB
  31. ));
  32. HRESULT hresult = NOERROR;
  33. ILockBytes *pLB;
  34. *pFLB = NULL;
  35. if (!(pLB = new MemLockBytes))
  36. {
  37. DEBUG_LEAVE_API(E_OUTOFMEMORY);
  38. return(E_OUTOFMEMORY);
  39. }
  40. hresult = StgGetFillLockByteILockBytes(pLB, pFLB);
  41. if (hresult != NOERROR)
  42. delete pLB;
  43. DEBUG_LEAVE_API(hresult);
  44. return(hresult);
  45. }
  46. HRESULT StgGetFillLockByteOnFile(OLECHAR *pwcFileName, IFillLockBytes **pFLB)
  47. {
  48. DEBUG_ENTER_API((DBG_API,
  49. Hresult,
  50. "StgGetFillLockByteOnFile",
  51. "%#x, %#x",
  52. pwcFileName, pFLB
  53. ));
  54. HRESULT hresult = NOERROR;
  55. ILockBytes *pLB;
  56. HANDLE fhandle;
  57. *pFLB = NULL;
  58. fhandle = CreateFileW(pwcFileName, GENERIC_READ | GENERIC_WRITE,
  59. FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_ALWAYS,
  60. FILE_ATTRIBUTE_NORMAL, NULL);
  61. if (fhandle == INVALID_HANDLE_VALUE)
  62. {
  63. DEBUG_LEAVE_API(E_FAIL);
  64. return(E_FAIL);
  65. }
  66. if (!(pLB = new FileLockBytes(fhandle)))
  67. {
  68. CloseHandle(fhandle);
  69. DEBUG_LEAVE_API(E_OUTOFMEMORY);
  70. return(E_OUTOFMEMORY);
  71. }
  72. hresult = StgGetFillLockByteILockBytes(pLB, pFLB);
  73. if (hresult != NOERROR)
  74. delete pLB;
  75. DEBUG_LEAVE_API(hresult);
  76. return(hresult);
  77. }
  78. HRESULT StgGetFillLockByteILockBytes(ILockBytes *pLB, IFillLockBytes **pFLB)
  79. {
  80. DEBUG_ENTER_API((DBG_API,
  81. Hresult,
  82. "StgGetFillLockByteILockBytes",
  83. "%#x, %#x",
  84. pLB, pFLB
  85. ));
  86. IFillLockBytes *flb;
  87. *pFLB = NULL;
  88. if (!(flb = new CAsyncLockBytes(pLB)))
  89. {
  90. DEBUG_LEAVE_API(E_OUTOFMEMORY);
  91. return(E_OUTOFMEMORY);
  92. }
  93. *pFLB = flb;
  94. DEBUG_LEAVE_API(NOERROR);
  95. return(NOERROR);
  96. }