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.

156 lines
3.8 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORPORATION
  4. *
  5. * TITLE: APDROPT.CPP
  6. *
  7. * VERSION: 1.0
  8. *
  9. * AUTHOR: ShaunIv
  10. *
  11. * DATE: 5/22/2001
  12. *
  13. * DESCRIPTION: Autoplay drop target
  14. *
  15. *******************************************************************************/
  16. #include "precomp.h"
  17. #pragma hdrstop
  18. #include "apdropt.h"
  19. #include "wiadefui.h"
  20. #include "runwiz.h"
  21. CWiaAutoPlayDropTarget::CWiaAutoPlayDropTarget()
  22. : m_cRef(1)
  23. {
  24. WIA_PUSHFUNCTION(TEXT("CWiaAutoPlayDropTarget::CWiaAutoPlayDropTarget"));
  25. DllAddRef();
  26. }
  27. CWiaAutoPlayDropTarget::~CWiaAutoPlayDropTarget()
  28. {
  29. WIA_PUSHFUNCTION(TEXT("CWiaAutoPlayDropTarget::~CWiaAutoPlayDropTarget"));
  30. DllRelease();
  31. }
  32. STDMETHODIMP_(ULONG) CWiaAutoPlayDropTarget::AddRef()
  33. {
  34. WIA_PUSHFUNCTION(TEXT("CWiaAutoPlayDropTarget::AddRef"));
  35. return InterlockedIncrement(&m_cRef);
  36. }
  37. STDMETHODIMP_(ULONG) CWiaAutoPlayDropTarget::Release()
  38. {
  39. WIA_PUSHFUNCTION(TEXT("CWiaAutoPlayDropTarget::Release"));
  40. LONG nRefCount = InterlockedDecrement(&m_cRef);
  41. if (!nRefCount)
  42. {
  43. delete this;
  44. }
  45. return nRefCount;
  46. }
  47. HRESULT CWiaAutoPlayDropTarget::QueryInterface( REFIID riid, void **ppvObject )
  48. {
  49. WIA_PUSHFUNCTION(TEXT("CWiaAutoPlayDropTarget::QueryInterface"));
  50. if (IsEqualIID( riid, IID_IUnknown ))
  51. {
  52. *ppvObject = static_cast<IDropTarget*>(this);
  53. }
  54. else if (IsEqualIID( riid, IID_IDropTarget ))
  55. {
  56. *ppvObject = static_cast<IDropTarget*>(this);
  57. }
  58. else
  59. {
  60. *ppvObject = NULL;
  61. return(E_NOINTERFACE);
  62. }
  63. reinterpret_cast<IUnknown*>(*ppvObject)->AddRef();
  64. return(S_OK);
  65. }
  66. HRESULT CWiaAutoPlayDropTarget::DragEnter(IDataObject *pDataObject, DWORD grfKeyState, POINTL ptl, DWORD *pdwEffect)
  67. {
  68. *pdwEffect = DROPEFFECT_COPY;
  69. return S_OK;
  70. }
  71. HRESULT CWiaAutoPlayDropTarget::DragOver(DWORD grfKeyState, POINTL ptl, DWORD *pdwEffect)
  72. {
  73. *pdwEffect = DROPEFFECT_COPY;
  74. return S_OK;
  75. }
  76. HRESULT CWiaAutoPlayDropTarget::DragLeave(void)
  77. {
  78. return S_OK;
  79. }
  80. HRESULT GetPathFromDataObject( IDataObject *pDataObject, LPTSTR pszPath, UINT cchPath )
  81. {
  82. FORMATETC fmte = { CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
  83. STGMEDIUM medium = {0};
  84. HRESULT hr = pDataObject->GetData(&fmte, &medium);
  85. if (SUCCEEDED(hr))
  86. {
  87. if (DragQueryFile((HDROP)medium.hGlobal, 0, pszPath, cchPath))
  88. hr = S_OK;
  89. else
  90. hr = E_FAIL;
  91. ReleaseStgMedium(&medium);
  92. }
  93. return hr;
  94. }
  95. HRESULT CWiaAutoPlayDropTarget::Drop( IDataObject *pDataObject, DWORD grfKeyState, POINTL pt, DWORD *pdwEffect )
  96. {
  97. WIA_PUSH_FUNCTION((TEXT("CWiaAutoPlayDropTarget::Drop")));
  98. //
  99. // Validate pointer arguments
  100. //
  101. if (!pDataObject || !pdwEffect)
  102. {
  103. return E_POINTER;
  104. }
  105. //
  106. // Get the path
  107. //
  108. WCHAR szPath[MAX_PATH] = {0};
  109. HRESULT hr = GetPathFromDataObject( pDataObject, szPath, ARRAYSIZE(szPath) );
  110. *pdwEffect = DROPEFFECT_COPY;
  111. if (SUCCEEDED(hr))
  112. {
  113. WIA_TRACE((TEXT("szPath: %ws"), szPath ));
  114. //
  115. // Make sure we have a string
  116. //
  117. if (lstrlen(szPath))
  118. {
  119. //
  120. // Create the device name, of the form {D:\\}, where D is the drive letter
  121. //
  122. WCHAR szDeviceID[MAX_PATH] = {0};
  123. wnsprintf( szDeviceID, ARRAYSIZE(szDeviceID), TEXT("{%ws}"), szPath );
  124. //
  125. // Run the wizard
  126. //
  127. hr = RunWiaWizard::RunWizard( szDeviceID );
  128. }
  129. else
  130. {
  131. hr = E_INVALIDARG;
  132. }
  133. }
  134. return hr;
  135. }