ReactOS  0.4.15-dev-492-ga1108f6
CDeskLinkDropHandler.cpp
Go to the documentation of this file.
1 /*
2  * PROJECT: sendmail
3  * LICENSE: LGPL-2.1+ (https://spdx.org/licenses/LGPL-2.1+)
4  * PURPOSE: DeskLink implementation
5  * COPYRIGHT: Copyright 2019 Katayama Hirofumi MZ (katayama.hirofumi.mz@gmail.com)
6  */
7 
8 #include "precomp.hpp"
9 
11 
13 {
15 }
16 
18 {
20 }
21 
22 // IDropTarget
25  POINTL pt, DWORD *pdwEffect)
26 {
27  TRACE("(%p)\n", this);
28 
29  *pdwEffect &= DROPEFFECT_LINK;
30 
31  return S_OK;
32 }
33 
36 {
37  TRACE("(%p)\n", this);
38 
39  *pdwEffect &= DROPEFFECT_LINK;
40 
41  return S_OK;
42 }
43 
45 {
46  TRACE("(%p)\n", this);
47  return S_OK;
48 }
49 
51 CDeskLinkDropHandler::Drop(IDataObject *pDataObject, DWORD dwKeyState,
52  POINTL pt, DWORD *pdwEffect)
53 {
54  TRACE("(%p)\n", this);
55 
56  if (!pDataObject)
57  {
58  ERR("pDataObject is NULL\n");
59  return E_POINTER;
60  }
61 
62  FORMATETC fmt;
64  fmt.ptd = NULL;
65  fmt.dwAspect = DVASPECT_CONTENT;
66  fmt.lindex = -1;
67  fmt.tymed = TYMED_HGLOBAL;
68 
69  WCHAR szDir[MAX_PATH], szDest[MAX_PATH], szSrc[MAX_PATH];
71 
72  CComPtr<IShellFolder> pDesktop;
73  HRESULT hr = SHGetDesktopFolder(&pDesktop);
75  return hr;
76 
77  STGMEDIUM medium;
78  hr = pDataObject->GetData(&fmt, &medium);
80  return hr;
81 
82  LPIDA pida = reinterpret_cast<LPIDA>(GlobalLock(medium.hGlobal));
83  if (!pida)
84  {
85  ERR("Error locking global\n");
86  ReleaseStgMedium(&medium);
87  return E_FAIL;
88  }
89 
90  LPBYTE pb = reinterpret_cast<LPBYTE>(pida);
91  LPCITEMIDLIST pidlParent = reinterpret_cast<LPCITEMIDLIST>(pb + pida->aoffset[0]);
92  for (UINT i = 1; i <= pida->cidl; ++i)
93  {
94  LPCITEMIDLIST pidlChild = reinterpret_cast<LPCITEMIDLIST>(pb + pida->aoffset[i]);
95 
96  CComHeapPtr<ITEMIDLIST> pidl(ILCombine(pidlParent, pidlChild));
97  if (!pidl)
98  {
99  ERR("Out of memory\n");
100  break;
101  }
102 
103  StringCbCopyW(szDest, sizeof(szDest), szDir);
104  if (SHGetPathFromIDListW(pidl, szSrc))
105  {
106  CStringW strTitle;
107  strTitle.Format(IDS_SHORTCUT, PathFindFileNameW(szSrc));
108 
109  PathAppendW(szDest, strTitle);
110  PathRemoveExtensionW(szDest);
111  StringCbCatW(szDest, sizeof(szDest), L".lnk");
112 
113  hr = CreateShellLink(szDest, szSrc, NULL, NULL, NULL, NULL, -1, NULL);
114  }
115  else
116  {
117  STRRET strret;
118  hr = pDesktop->GetDisplayNameOf(pidl, SHGDN_INFOLDER, &strret);
119  if (FAILED_UNEXPECTEDLY(hr))
120  break;
121 
122  hr = StrRetToBufW(&strret, pidl, szSrc, _countof(szSrc));
123  if (FAILED_UNEXPECTEDLY(hr))
124  break;
125 
126  CStringW strTitle;
127  strTitle.Format(IDS_SHORTCUT, szSrc);
128 
129  PathAppendW(szDest, strTitle);
130  PathRemoveExtensionW(szDest);
131  StringCbCatW(szDest, sizeof(szDest), L".lnk");
132 
133  hr = CreateShellLink(szDest, NULL, pidl, NULL, NULL, NULL, -1, NULL);
134  }
135 
136  if (FAILED_UNEXPECTEDLY(hr))
137  break;
138  }
139 
140  GlobalUnlock(medium.hGlobal);
141  ReleaseStgMedium(&medium);
142 
143  return hr;
144 }
145 
146 // IPersistFile
148 {
149  FIXME("(%p)\n", this);
150  return E_NOTIMPL;
151 }
152 
154 {
155  FIXME("(%p)\n", this);
156  return E_NOTIMPL;
157 }
158 
160 {
161  return S_OK;
162 }
163 
165 {
166  FIXME("(%p)\n", this);
167  return E_NOTIMPL;
168 }
169 
171 {
172  FIXME("(%p)\n", this);
173  return E_NOTIMPL;
174 }
175 
176 // IPersist
178 {
179  TRACE("(%p)\n", this);
180 
181  if (!lpClassId)
182  {
183  ERR("lpClassId is NULL\n");
184  return E_POINTER;
185  }
186 
187  *lpClassId = CLSID_DeskLinkDropHandler;
188 
189  return S_OK;
190 }
#define CFSTR_SHELLIDLIST
Definition: shlobj.h:477
HRESULT hr
Definition: shlfolder.c:183
void WINAPI ReleaseStgMedium(STGMEDIUM *pmedium)
Definition: ole2.c:2033
#define pt(x, y)
Definition: drawing.c:79
UINT WINAPI RegisterClipboardFormatW(_In_ LPCWSTR)
LONG g_ModuleRefCnt
Definition: ACPPage.cpp:13
HRESULT WINAPI StrRetToBufW(LPSTRRET src, const ITEMIDLIST *pidl, LPWSTR dest, UINT len)
Definition: string.c:1522
LPITEMIDLIST WINAPI ILCombine(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
Definition: pidl.c:699
const ITEMIDLIST UNALIGNED * LPCITEMIDLIST
Definition: shtypes.idl:42
BOOL WINAPI SHGetPathFromIDListW(LPCITEMIDLIST pidl, LPWSTR pszPath)
Definition: pidl.c:1288
const char * fmt
Definition: wsprintf.c:30
HRESULT GetData([in, unique] FORMATETC *pformatetcIn, [out] STGMEDIUM *pmedium)
STDMETHODIMP GetCurFile(LPOLESTR *ppszFileName)
void __cdecl Format(UINT nFormatID,...)
Definition: cstringt.h:688
#define IDS_SHORTCUT
Definition: resource.h:12
static LPOLESTR
Definition: stg_prop.c:27
STDMETHODIMP Drop(IDataObject *pDataObject, DWORD dwKeyState, POINTL pt, DWORD *pdwEffect)
#define E_FAIL
Definition: ddrawi.h:102
STRSAFEAPI StringCbCatW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:342
BOOL WINAPI PathAppendW(LPWSTR lpszPath, LPCWSTR lpszAppend)
Definition: path.c:121
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
unsigned char * LPBYTE
Definition: typedefs.h:53
void WINAPI PathRemoveExtensionW(LPWSTR lpszPath)
Definition: path.c:818
unsigned int BOOL
Definition: ntddk_ex.h:94
#define FIXME(fmt,...)
Definition: debug.h:111
WORD WORD PSZ PSZ pszFileName
Definition: vdmdbg.h:41
#define STDMETHODIMP
Definition: basetyps.h:43
smooth NULL
Definition: ftsmooth.c:416
LPWSTR WINAPI PathFindFileNameW(LPCWSTR lpszPath)
Definition: path.c:389
#define TRACE(s)
Definition: solgame.cpp:4
HRESULT WINAPI SHGetDesktopFolder(IShellFolder **psf)
STDMETHODIMP DragOver(DWORD dwKeyState, POINTL pt, DWORD *pdwEffect)
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:78
#define _countof(array)
Definition: sndvol32.h:68
#define FAILED_UNEXPECTEDLY(hr)
Definition: shellutils.h:71
#define MAX_PATH
Definition: compat.h:26
const DWORD DROPEFFECT_LINK
Definition: oleidl.idl:932
UINT cidl
Definition: shlobj.h:499
unsigned long DWORD
Definition: ntddk_ex.h:95
static const WCHAR L[]
Definition: oid.c:1250
LPVOID NTAPI GlobalLock(HGLOBAL hMem)
Definition: heapmem.c:755
#define InterlockedDecrement
Definition: armddk.h:52
STDMETHODIMP Save(LPCOLESTR pszFileName, BOOL fRemember)
WINE_DEFAULT_DEBUG_CHANNEL(sendmail)
STDMETHODIMP GetClassID(CLSID *lpClassId)
#define ERR(fmt,...)
Definition: debug.h:110
STDMETHODIMP Load(LPCOLESTR pszFileName, DWORD dwMode)
#define S_OK
Definition: intsafe.h:59
STDMETHODIMP SaveCompleted(LPCOLESTR pszFileName)
#define InterlockedIncrement
Definition: armddk.h:53
BOOL WINAPI SHGetSpecialFolderPathW(HWND hwndOwner, LPWSTR szPath, int nFolder, BOOL bCreate)
Definition: shellpath.c:2709
#define E_NOTIMPL
Definition: ddrawi.h:99
HRESULT CreateShellLink(LPCWSTR pszLinkPath, LPCWSTR pszTargetPath OPTIONAL, LPCITEMIDLIST pidlTarget OPTIONAL, LPCWSTR pszArg OPTIONAL, LPCWSTR pszDir OPTIONAL, LPCWSTR pszIconPath OPTIONAL, INT iIconNr OPTIONAL, LPCWSTR pszComment OPTIONAL)
Definition: sendmail.cpp:102
UINT aoffset[1]
Definition: shlobj.h:500
unsigned int UINT
Definition: ndis.h:50
BOOL NTAPI GlobalUnlock(HGLOBAL hMem)
Definition: heapmem.c:1190
STDMETHODIMP DragEnter(IDataObject *pDataObject, DWORD dwKeyState, POINTL pt, DWORD *pdwEffect)
#define CSIDL_DESKTOPDIRECTORY
Definition: shlobj.h:2027
#define E_POINTER
Definition: winerror.h:2365
STRSAFEAPI StringCbCopyW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:166
Definition: dsound.c:943
Definition: shlobj.h:498