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.

55 lines
1.3 KiB

  1. // MLSWalk.cpp : Implementation of CMLStrWalkW
  2. #include "private.h"
  3. #include "mlswalk.h"
  4. /////////////////////////////////////////////////////////////////////////////
  5. // CMLStrWalkW
  6. BOOL CMLStrWalkW::Lock(HRESULT& rhr)
  7. {
  8. if (m_pszBuf)
  9. rhr = E_FAIL; // Already locked
  10. if (SUCCEEDED(rhr) &&
  11. m_lLen > 0 &&
  12. FAILED(rhr = m_pMLStr->LockWStr(m_lPos, m_lLen, m_lFlags, 0, &m_pszBuf, &m_cchBuf, &m_lLockLen)))
  13. {
  14. m_pszBuf = NULL; // Mark as it's not locked
  15. }
  16. if (m_fCanStopAtMiddle && FAILED(rhr) && m_lDoneLen > 0)
  17. {
  18. rhr = S_OK;
  19. return FALSE; // Stop it, but not fail
  20. }
  21. else
  22. {
  23. return (SUCCEEDED(rhr) && m_lLen > 0);
  24. }
  25. }
  26. void CMLStrWalkW::Unlock(HRESULT& rhr, long lActualLen)
  27. {
  28. HRESULT hr = S_OK;
  29. if (!m_pszBuf)
  30. hr = E_FAIL; // Not locked yet
  31. if (SUCCEEDED(hr) &&
  32. SUCCEEDED(hr = m_pMLStr->UnlockWStr(m_pszBuf, 0, NULL, NULL))) // Unlock even if rhr is already failed
  33. {
  34. if (!lActualLen)
  35. lActualLen = m_lLockLen;
  36. else
  37. ASSERT(lActualLen > 0 && lActualLen <= m_lLockLen);
  38. m_lPos += lActualLen;
  39. m_lLen -= lActualLen;
  40. m_lDoneLen += lActualLen;
  41. }
  42. m_pszBuf = NULL; // Unlock anyway
  43. if (SUCCEEDED(rhr))
  44. rhr = hr; // if rhr is failed before UnlockBuf, use it
  45. }