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.

150 lines
4.2 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORP., 1998
  4. *
  5. * TITLE: Extras.Cpp
  6. *
  7. * DESCRIPTION:
  8. * Implementation of IWiaItemExtras methods
  9. *
  10. *******************************************************************************/
  11. #include "precomp.h"
  12. #include "stiexe.h"
  13. HRESULT CWiaItem::GetExtendedErrorInfo(BSTR *bstrRet)
  14. {
  15. HRESULT hr = S_OK;
  16. WCHAR *pDevErrStr = NULL;
  17. LONG lDevErrVal = 0;
  18. if (bstrRet) {
  19. *bstrRet = NULL;
  20. //
  21. // Call the driver to give us an error string
  22. //
  23. hr = m_pActiveDevice->m_DrvWrapper.WIA_drvGetDeviceErrorStr(
  24. 0,
  25. m_lLastDevErrVal,
  26. &pDevErrStr,
  27. &lDevErrVal);
  28. //
  29. // Overwrite the device error value with the new one.
  30. //
  31. m_lLastDevErrVal = lDevErrVal;
  32. if (SUCCEEDED(hr)) {
  33. //
  34. // Make a BSTR out of the returned string
  35. //
  36. if (pDevErrStr) {
  37. *bstrRet = SysAllocString(pDevErrStr);
  38. if (!(*bstrRet)) {
  39. DBG_ERR(("CWiaItem::GetExtendedErrorInfo, out of memory!"));
  40. hr = E_OUTOFMEMORY;
  41. }
  42. //
  43. // Free the returned string
  44. //
  45. CoTaskMemFree(pDevErrStr);
  46. pDevErrStr = NULL;
  47. } else {
  48. DBG_ERR(("CWiaItem::GetExtendedErrorInfo, Driver's drvGetDeviceErrorStr return success, but failed to return a string!"));
  49. hr = WIA_ERROR_INVALID_DRIVER_RESPONSE;
  50. }
  51. }
  52. } else {
  53. DBG_WRN(("CWiaItem::GetExtendedErrorInfo, NULL argument passed"));
  54. hr = E_INVALIDARG;
  55. }
  56. return hr;
  57. }
  58. HRESULT CWiaItem::Escape(
  59. DWORD EscapeFunction,
  60. LPBYTE lpInData,
  61. DWORD cbInDataSize,
  62. LPBYTE pOutData,
  63. DWORD dwOutDataSize,
  64. LPDWORD pdwActualData)
  65. {
  66. DBG_FN(CWiaItem::Escape);
  67. HRESULT hr = E_UNEXPECTED;
  68. //
  69. // Do some parameter validation. This shouldn't be necessary since
  70. // COM should have done it for us, but this is a paranoid check in
  71. // case we call it internally somewhere (and so skip COM validation).
  72. //
  73. if (IsBadReadPtr(lpInData, cbInDataSize)) {
  74. DBG_WRN(("CWiaItem::Escape, Input buffer is a bad read pointer (could not read cbInDataSize bytes)"));
  75. return E_INVALIDARG;
  76. }
  77. if (IsBadWritePtr(pOutData, dwOutDataSize)) {
  78. DBG_WRN(("CWiaItem::Escape, Output buffer is a bad write pointer (cannot write dwOutDataSize bytes)"));
  79. return E_INVALIDARG;
  80. }
  81. //
  82. // Everything OK so far, so make the Escape call
  83. //
  84. if (m_pActiveDevice) {
  85. LOCK_WIA_DEVICE _LWD(this, &hr);
  86. if(SUCCEEDED(hr)) {
  87. hr = m_pActiveDevice->m_DrvWrapper.STI_Escape(EscapeFunction,
  88. lpInData,
  89. cbInDataSize,
  90. pOutData,
  91. dwOutDataSize,
  92. pdwActualData);
  93. }
  94. }
  95. return hr;
  96. }
  97. HRESULT CWiaItem::CancelPendingIO()
  98. {
  99. HRESULT hr = S_OK;
  100. //
  101. // Driver interface must be valid.
  102. //
  103. if (!m_pActiveDevice) {
  104. DBG_ERR(("CWiaItem::CancelPendingIO, bad mini driver interface"));
  105. return E_FAIL;
  106. }
  107. //
  108. // Corresponding driver item must be valid.
  109. //
  110. hr = ValidateWiaDrvItemAccess(m_pWiaDrvItem);
  111. if (FAILED(hr)) {
  112. DBG_ERR(("CWiaItem::CancelPendingIO, ValidateWiaDrvItemAccess failed (0x%X)", hr));
  113. return hr;
  114. }
  115. //
  116. // no need to take any locks -- this method should be fully
  117. // asynchronous.
  118. //
  119. hr = m_pActiveDevice->m_DrvWrapper.WIA_drvNotifyPnpEvent(&WIA_EVENT_CANCEL_IO, NULL, 0);
  120. if (FAILED(hr)) {
  121. DBG_ERR(("CWiaItem::CancelPendingIO, drvNotifyPnpEvent failed (0x%X)", hr));
  122. return hr;
  123. }
  124. return hr;
  125. }