ReactOS  0.4.15-dev-1389-g828d5fa
desktopipc.cpp File Reference
#include "precomp.h"
#include <shlwapi.h>
#include <shlwapi_undoc.h>
Include dependency graph for desktopipc.cpp:

Go to the source code of this file.

Classes

struct  HNFBlock
 
class  CProxyDesktop
 

Macros

#define PROXY_DESKTOP_CLASS   L"Proxy Desktop"
 

Functions

HWND FindShellProxy (LPITEMIDLIST pidl)
 
HANDLE MakeSharedPacket (IEThreadParamBlock *threadParams, LPCWSTR strPath, int dwProcessId)
 
PIE_THREAD_PARAM_BLOCK ParseSharedPacket (HANDLE hData)
 
static HRESULT ExplorerMessageLoop (IEThreadParamBlock *parameters)
 
static DWORD WINAPI BrowserThreadProc (LPVOID lpThreadParameter)
 
IEThreadParamBlock *WINAPI SHCreateIETHREADPARAM (long param8, long paramC, IUnknown *param10, IUnknown *param14)
 
IEThreadParamBlock *WINAPI SHCloneIETHREADPARAM (IEThreadParamBlock *param)
 
void WINAPI SHDestroyIETHREADPARAM (IEThreadParamBlock *param)
 
BOOL WINAPI SHOnCWMCommandLine (HANDLE hSharedInfo)
 
HRESULT WINAPI SHOpenFolderWindow (PIE_THREAD_PARAM_BLOCK parameters)
 
HRESULT WINAPI SHOpenNewFrame (LPITEMIDLIST pidl, IUnknown *paramC, long param10, DWORD dwFlags)
 
BOOL WINAPI SHCreateFromDesktop (ExplorerCommandLineParseResults *parseResults)
 

Variables

BOOL g_SeparateFolders = FALSE
 
HWND g_hwndProxyDesktop = NULL
 

Macro Definition Documentation

◆ PROXY_DESKTOP_CLASS

#define PROXY_DESKTOP_CLASS   L"Proxy Desktop"

Definition at line 5 of file desktopipc.cpp.

Function Documentation

◆ BrowserThreadProc()

static DWORD WINAPI BrowserThreadProc ( LPVOID  lpThreadParameter)
static

Definition at line 428 of file desktopipc.cpp.

429 {
430  IEThreadParamBlock * parameters = (IEThreadParamBlock *) lpThreadParameter;
431 
433  ExplorerMessageLoop(parameters);
434 
435  /* Destroying the parameters releases the thread reference */
436  SHDestroyIETHREADPARAM(parameters);
437 
438  /* Wake up the proxy desktop thread so it can check whether the last browser thread exited */
439  /* Use PostMessage in order to force GetMessage to return and check if all browser windows have exited */
441 
442  OleUninitialize();
443 
444  return 0;
445 }
HWND FindShellProxy(LPITEMIDLIST pidl)
Definition: desktopipc.cpp:69
static HRESULT ExplorerMessageLoop(IEThreadParamBlock *parameters)
Definition: desktopipc.cpp:344
HRESULT WINAPI DECLSPEC_HOTPATCH OleInitialize(LPVOID reserved)
Definition: ole2.c:169
void WINAPI SHDestroyIETHREADPARAM(IEThreadParamBlock *param)
Definition: desktopipc.cpp:502
#define NULL
Definition: types.h:112
BOOL WINAPI PostMessageW(_In_opt_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
void WINAPI DECLSPEC_HOTPATCH OleUninitialize(void)
Definition: ole2.c:230
#define WM_EXPLORER_1037

Referenced by SHOpenFolderWindow().

◆ ExplorerMessageLoop()

static HRESULT ExplorerMessageLoop ( IEThreadParamBlock parameters)
static

Definition at line 344 of file desktopipc.cpp.

345 {
346  HRESULT hResult;
347  MSG Msg;
348  BOOL Ret;
349 
350  // Tell the thread ref we are using it.
351  if (parameters && parameters->offsetF8)
352  parameters->offsetF8->AddRef();
353 
354  /* Handle /e parameter */
355  UINT wFlags = 0;
356  if ((parameters->dwFlags & SH_EXPLORER_CMDLINE_FLAG_E))
357  wFlags |= SBSP_EXPLOREMODE;
358 
359  /* Handle /select parameter */
360  PUITEMID_CHILD pidlSelect = NULL;
361  if ((parameters->dwFlags & SH_EXPLORER_CMDLINE_FLAG_SELECT) &&
362  (ILGetNext(parameters->directoryPIDL) != NULL))
363  {
364  pidlSelect = ILClone(ILFindLastID(parameters->directoryPIDL));
365  ILRemoveLastID(parameters->directoryPIDL);
366  }
367 
370  if (FAILED_UNEXPECTEDLY(hResult))
371  return hResult;
372 
373  hResult = psb->BrowseObject(parameters->directoryPIDL, wFlags);
374  if (FAILED_UNEXPECTEDLY(hResult))
375  return hResult;
376 
377  if (pidlSelect != NULL)
378  {
379  CComPtr<IShellView> shellView;
380  hResult = psb->QueryActiveShellView(&shellView);
381  if (SUCCEEDED(hResult))
382  {
383  shellView->SelectItem(pidlSelect, SVSI_SELECT | SVSI_FOCUSED | SVSI_ENSUREVISIBLE);
384  }
385  ILFree(pidlSelect);
386  }
387 
389  hResult = psb->QueryInterface(IID_PPV_ARG(IBrowserService2, &browser));
390  if (FAILED_UNEXPECTEDLY(hResult))
391  return hResult;
392 
393  psb.Release();
394 
395  while ((Ret = GetMessage(&Msg, NULL, 0, 0)) != 0)
396  {
397  if (Ret == -1)
398  {
399  // Error: continue or exit?
400  break;
401  }
402 
403  if (Msg.message == WM_QUIT)
404  break;
405 
406  if (browser->v_MayTranslateAccelerator(&Msg) != S_OK)
407  {
410  }
411  }
412 
413  int nrc = browser->Release();
414  if (nrc > 0)
415  {
416  DbgPrint("WARNING: There are %d references to the CShellBrowser active or leaked.\n", nrc);
417  }
418 
419  browser.Detach();
420 
421  // Tell the thread ref we are not using it anymore.
422  if (parameters && parameters->offsetF8)
423  parameters->offsetF8->Release();
424 
425  return hResult;
426 }
#define DispatchMessage
Definition: winuser.h:5740
BOOL WINAPI TranslateMessage(_In_ const MSG *)
void WINAPI ILFree(LPITEMIDLIST pidl)
Definition: pidl.c:925
#define DbgPrint
Definition: loader.c:25
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1827
ITEMID_CHILD UNALIGNED * PUITEMID_CHILD
Definition: shtypes.idl:68
LPITEMIDLIST WINAPI ILGetNext(LPCITEMIDLIST pidl)
Definition: pidl.c:851
#define WM_QUIT
Definition: winuser.h:1605
BOOL WINAPI ILRemoveLastID(LPITEMIDLIST pidl)
Definition: pidl.c:212
#define IID_PPV_ARG(Itype, ppType)
struct @1620 Msg[]
HRESULT CShellBrowser_CreateInstance(REFIID riid, void **ppv)
unsigned int BOOL
Definition: ntddk_ex.h:94
if SUCCEEDED(hr)
#define SH_EXPLORER_CMDLINE_FLAG_E
ULONG Release()
LPITEMIDLIST WINAPI ILFindLastID(LPCITEMIDLIST pidl)
Definition: pidl.c:189
LONG HRESULT
Definition: typedefs.h:79
#define FAILED_UNEXPECTEDLY(hr)
Definition: shellutils.h:71
ULONG AddRef()
_In_ DWORD _Out_ _In_ WORD wFlags
Definition: wincon.h:534
#define S_OK
Definition: intsafe.h:51
LPITEMIDLIST WINAPI ILClone(LPCITEMIDLIST pidl)
Definition: pidl.c:228
void Release()
Definition: atlcomcli.h:140
unsigned int UINT
Definition: ndis.h:50
#define NULL
Definition: types.h:112
#define GetMessage
Definition: winuser.h:5765
T * Detach()
Definition: atlcomcli.h:156
#define SH_EXPLORER_CMDLINE_FLAG_SELECT
LPITEMIDLIST directoryPIDL

Referenced by BrowserThreadProc().

◆ FindShellProxy()

HWND FindShellProxy ( LPITEMIDLIST  pidl)

Definition at line 69 of file desktopipc.cpp.

70 {
71  /* If there is a proxy desktop in the current process use it */
73  return g_hwndProxyDesktop;
74 
75  /* Try to find the desktop of the main explorer process */
76  if (!g_SeparateFolders)
77  {
79 
80  if (shell)
81  {
82  TRACE("Found main desktop.\n");
83  return shell;
84  }
85  }
86  else
87  {
88  TRACE("Separate folders setting enabled. Ignoring main desktop.\n");
89  }
90 
91  /* The main desktop can't be find so try to see if another process has a proxy desktop */
93  if (proxy)
94  {
95  TRACE("Found proxy desktop.\n");
96  return proxy;
97  }
98 
99  return NULL;
100 }
HWND WINAPI GetShellWindow(VOID)
Definition: desktop.c:651
int proxy
Definition: main.c:67
#define FindWindow
Definition: winuser.h:5752
#define TRACE(s)
Definition: solgame.cpp:4
HWND g_hwndProxyDesktop
Definition: desktopipc.cpp:8
void shell(int argc, const char *argv[])
Definition: cmds.c:1231
#define NULL
Definition: types.h:112
BOOL g_SeparateFolders
Definition: desktopipc.cpp:7
#define PROXY_DESKTOP_CLASS
Definition: desktopipc.cpp:5

Referenced by BrowserThreadProc(), and SHCreateFromDesktop().

◆ MakeSharedPacket()

HANDLE MakeSharedPacket ( IEThreadParamBlock threadParams,
LPCWSTR  strPath,
int  dwProcessId 
)

Definition at line 102 of file desktopipc.cpp.

103 {
104  HNFBlock* hnfData;
105  UINT sharedBlockSize = sizeof(*hnfData);
106  UINT directoryPidlLength = 0;
107  UINT pidlSize7C = 0;
108  UINT pidlSize80 = 0;
109  UINT pathLength = 0;
110  LPITEMIDLIST pidl80 = threadParams->offset80;
111 
112  // Count the total length of the message packet
113 
114  // directory PIDL
115  if (threadParams->directoryPIDL)
116  {
117  directoryPidlLength = ILGetSize(threadParams->directoryPIDL);
118  sharedBlockSize += directoryPidlLength;
119  TRACE("directoryPidlLength=%d\n", directoryPidlLength);
120  }
121 
122  // another PIDL
123  if (threadParams->offset7C)
124  {
125  pidlSize7C = ILGetSize(threadParams->offset7C);
126  sharedBlockSize += pidlSize7C;
127  TRACE("pidlSize7C=%d\n", pidlSize7C);
128  }
129 
130  // This flag indicates the presence of another pidl?
131  if (!(threadParams->offset84 & 0x8000))
132  {
133  if (pidl80)
134  {
135  pidlSize80 = ILGetSize(pidl80);
136  sharedBlockSize += pidlSize80;
137  TRACE("pidlSize80=%d\n", pidlSize7C);
138  }
139  }
140  else
141  {
142  TRACE("pidl80 sent by value = %p\n", pidl80);
143  pidlSize80 = 4;
144  sharedBlockSize += pidlSize80;
145  }
146 
147  // The path string
148  if (strPath)
149  {
150  pathLength = 2 * lstrlenW(strPath) + 2;
151  sharedBlockSize += pathLength;
152  TRACE("pathLength=%d\n", pidlSize7C);
153  }
154 
155  TRACE("sharedBlockSize=%d\n", sharedBlockSize);
156 
157  // Allocate and fill the shared section
158  HANDLE hShared = SHAllocShared(0, sharedBlockSize, dwProcessId);
159  if (!hShared)
160  {
161  ERR("Shared section alloc error.\n");
162  return 0;
163  }
164 
165  PBYTE target = (PBYTE) SHLockShared(hShared, dwProcessId);
166  if (!target)
167  {
168  ERR("Shared section lock error. %d\n", GetLastError());
169  SHFreeShared(hShared, dwProcessId);
170  return 0;
171  }
172 
173  // Basic information
174  hnfData = (HNFBlock*) target;
175  hnfData->cbSize = sharedBlockSize;
176  hnfData->offset4 = (DWORD) (threadParams->dwFlags);
177  hnfData->offset8 = (DWORD) (threadParams->offset8);
178  hnfData->offsetC = (DWORD) (threadParams->offset74);
179  hnfData->offset10 = (DWORD) (threadParams->offsetD8);
180  hnfData->offset14 = (DWORD) (threadParams->offset84);
181  hnfData->offset18 = (DWORD) (threadParams->offset88);
182  hnfData->offset1C = (DWORD) (threadParams->offset8C);
183  hnfData->offset20 = (DWORD) (threadParams->offset90);
184  hnfData->offset24 = (DWORD) (threadParams->offset94);
185  hnfData->offset28 = (DWORD) (threadParams->offset98);
186  hnfData->offset2C = (DWORD) (threadParams->offset9C);
187  hnfData->offset30 = (DWORD) (threadParams->offsetA0);
188  hnfData->directoryPidlLength = 0;
189  hnfData->pidlSize7C = 0;
190  hnfData->pidlSize80 = 0;
191  hnfData->pathLength = 0;
192  target += sizeof(*hnfData);
193 
194  // Copy the directory pidl contents
195  if (threadParams->directoryPIDL)
196  {
197  memcpy(target, threadParams->directoryPIDL, directoryPidlLength);
198  target += directoryPidlLength;
199  hnfData->directoryPidlLength = directoryPidlLength;
200  }
201 
202  // Copy the other pidl contents
203  if (threadParams->offset7C)
204  {
205  memcpy(target, threadParams->offset7C, pidlSize7C);
206  target += pidlSize7C;
207  hnfData->pidlSize7C = pidlSize7C;
208  }
209 
210  // copy the third pidl
211  if (threadParams->offset84 & 0x8000)
212  {
213  *(LPITEMIDLIST*) target = pidl80;
214  target += pidlSize80;
215  hnfData->pidlSize80 = pidlSize80;
216  }
217  else if (pidl80)
218  {
219  memcpy(target, pidl80, pidlSize80);
220  target += pidlSize80;
221  hnfData->pidlSize80 = pidlSize80;
222  }
223 
224  // and finally the path string
225  if (strPath)
226  {
227  memcpy(target, strPath, pathLength);
228  hnfData->pathLength = pathLength;
229  }
230 
231  SHUnlockShared(hnfData);
232 
233  return hShared;
234 }
UINT pidlSize7C
Definition: desktopipc.cpp:27
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1044
DWORD offset20
Definition: desktopipc.cpp:21
#define lstrlenW
Definition: compat.h:609
UINT pidlSize80
Definition: desktopipc.cpp:28
#define DWORD
Definition: nt_native.h:44
DWORD offset10
Definition: desktopipc.cpp:17
LPITEMIDLIST offset80
DWORD offsetC
Definition: desktopipc.cpp:16
UINT cbSize
Definition: desktopipc.cpp:13
DWORD offset8
Definition: desktopipc.cpp:15
DWORD offset28
Definition: desktopipc.cpp:23
LPITEMIDLIST offset7C
#define TRACE(s)
Definition: solgame.cpp:4
HANDLE WINAPI SHAllocShared(LPCVOID lpvData, DWORD dwSize, DWORD dwProcId)
Definition: ordinal.c:162
DWORD offset2C
Definition: desktopipc.cpp:24
DWORD offset30
Definition: desktopipc.cpp:25
BOOL WINAPI SHFreeShared(HANDLE hShared, DWORD dwProcId)
Definition: ordinal.c:308
UINT pathLength
Definition: desktopipc.cpp:29
DWORD offset4
Definition: desktopipc.cpp:14
DWORD offset14
Definition: desktopipc.cpp:18
DWORD offset1C
Definition: desktopipc.cpp:20
UINT directoryPidlLength
Definition: desktopipc.cpp:26
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define ERR(fmt,...)
Definition: debug.h:110
DWORD offset24
Definition: desktopipc.cpp:22
PVOID WINAPI SHLockShared(HANDLE hShared, DWORD dwProcId)
Definition: ordinal.c:252
unsigned int UINT
Definition: ndis.h:50
DWORD offset18
Definition: desktopipc.cpp:19
#define ILGetSize
Definition: shellclasses.h:638
BOOL WINAPI SHUnlockShared(LPVOID lpView)
Definition: ordinal.c:288
GLenum target
Definition: glext.h:7315
ITEMIDLIST UNALIGNED * LPITEMIDLIST
Definition: shtypes.idl:41
BYTE * PBYTE
Definition: pedump.c:66
LPITEMIDLIST directoryPIDL

Referenced by SHCreateFromDesktop().

◆ ParseSharedPacket()

PIE_THREAD_PARAM_BLOCK ParseSharedPacket ( HANDLE  hData)

Definition at line 236 of file desktopipc.cpp.

237 {
238  HNFBlock * hnfData;
239  PBYTE block;
240  int pid;
242 
243  if (!hData)
244  goto cleanup0;
245 
247  block = (PBYTE) SHLockShared(hData, pid);
248 
249  hnfData = (HNFBlock *) block;
250  if (!block)
251  goto cleanup2;
252 
253  if (hnfData->cbSize < sizeof(HNFBlock))
254  goto cleanup2;
255 
256  params = SHCreateIETHREADPARAM(0, hnfData->offset8, 0, 0);
257  if (!params)
258  goto cleanup2;
259 
260  params->dwFlags = hnfData->offset4;
261  params->offset8 = hnfData->offset8;
262  params->offset74 = hnfData->offsetC;
263  params->offsetD8 = hnfData->offset10;
264  params->offset84 = hnfData->offset14;
265  params->offset88 = hnfData->offset18;
266  params->offset8C = hnfData->offset1C;
267  params->offset90 = hnfData->offset20;
268  params->offset94 = hnfData->offset24;
269  params->offset98 = hnfData->offset28;
270  params->offset9C = hnfData->offset2C;
271  params->offsetA0 = hnfData->offset30;
272 
273  block += sizeof(*hnfData);
274  if (hnfData->directoryPidlLength)
275  {
276  LPITEMIDLIST pidl = NULL;
277  if (*block)
278  pidl = ILClone((LPITEMIDLIST) block);
279  params->directoryPIDL = pidl;
280 
281  block += hnfData->directoryPidlLength;
282  }
283 
284  if (hnfData->pidlSize7C)
285  {
286  LPITEMIDLIST pidl = NULL;
287  if (*block)
288  pidl = ILClone((LPITEMIDLIST) block);
289  params->offset7C = pidl;
290 
291  block += hnfData->pidlSize80;
292  }
293 
294  if (hnfData->pidlSize80)
295  {
296  if (!(params->offset84 & 0x8000))
297  {
298  params->offset80 = *(LPITEMIDLIST *) block;
299  }
300  else
301  {
302  LPITEMIDLIST pidl = NULL;
303  if (*block)
304  pidl = ILClone((LPITEMIDLIST) block);
305  params->offset80 = pidl;
306  }
307 
308  block += hnfData->pidlSize80;
309  }
310 
311  if (hnfData->pathLength)
312  {
313  CComPtr<IShellFolder> psfDesktop;
314  PWSTR strPath = (PWSTR) block;
315 
316  if (FAILED(SHGetDesktopFolder(&psfDesktop)))
317  {
318  params->directoryPIDL = NULL;
319  goto cleanup0;
320  }
321 
322  if (FAILED(psfDesktop->ParseDisplayName(NULL, NULL, strPath, NULL, &params->directoryPIDL, NULL)))
323  {
324  params->directoryPIDL = NULL;
325  goto cleanup0;
326  }
327  }
328 
329 cleanup2:
330  SHUnlockShared(hnfData);
331  SHFreeShared(hData, pid);
332 
333 cleanup0:
334  if (!params->directoryPIDL)
335  {
337  return NULL;
338  }
339 
340  return params;
341 }
static unsigned int block
Definition: xmlmemory.c:118
_In_ ULONG_PTR _In_ ULONG _Out_ ULONG_PTR * pid
Definition: winddi.h:3835
UINT pidlSize7C
Definition: desktopipc.cpp:27
uint16_t * PWSTR
Definition: typedefs.h:56
DWORD offset20
Definition: desktopipc.cpp:21
UINT pidlSize80
Definition: desktopipc.cpp:28
DWORD offset10
Definition: desktopipc.cpp:17
DWORD offsetC
Definition: desktopipc.cpp:16
UINT cbSize
Definition: desktopipc.cpp:13
GLenum const GLfloat * params
Definition: glext.h:5645
DWORD offset8
Definition: desktopipc.cpp:15
DWORD offset28
Definition: desktopipc.cpp:23
HRESULT WINAPI SHGetDesktopFolder(IShellFolder **psf)
DWORD offset2C
Definition: desktopipc.cpp:24
DWORD offset30
Definition: desktopipc.cpp:25
BOOL WINAPI SHFreeShared(HANDLE hShared, DWORD dwProcId)
Definition: ordinal.c:308
UINT pathLength
Definition: desktopipc.cpp:29
DWORD offset4
Definition: desktopipc.cpp:14
DWORD offset14
Definition: desktopipc.cpp:18
DWORD offset1C
Definition: desktopipc.cpp:20
UINT directoryPidlLength
Definition: desktopipc.cpp:26
IEThreadParamBlock *WINAPI SHCreateIETHREADPARAM(long param8, long paramC, IUnknown *param10, IUnknown *param14)
Definition: desktopipc.cpp:450
DWORD offset24
Definition: desktopipc.cpp:22
void WINAPI SHDestroyIETHREADPARAM(IEThreadParamBlock *param)
Definition: desktopipc.cpp:502
LPITEMIDLIST WINAPI ILClone(LPCITEMIDLIST pidl)
Definition: pidl.c:228
PVOID WINAPI SHLockShared(HANDLE hShared, DWORD dwProcId)
Definition: ordinal.c:252
#define NULL
Definition: types.h:112
DWORD offset18
Definition: desktopipc.cpp:19
BOOL WINAPI SHUnlockShared(LPVOID lpView)
Definition: ordinal.c:288
ITEMIDLIST UNALIGNED * LPITEMIDLIST
Definition: shtypes.idl:41
BYTE * PBYTE
Definition: pedump.c:66
DWORD WINAPI GetCurrentProcessId(VOID)
Definition: proc.c:1158

Referenced by SHOnCWMCommandLine().

◆ SHCloneIETHREADPARAM()

IEThreadParamBlock* WINAPI SHCloneIETHREADPARAM ( IEThreadParamBlock param)

Definition at line 474 of file desktopipc.cpp.

475 {
477 
478  TRACE("SHCloneIETHREADPARAM\n");
479 
481  if (result == NULL)
482  return NULL;
483  memcpy(result, param, 0x40 * 4);
484  if (result->directoryPIDL != NULL)
485  result->directoryPIDL = ILClone(result->directoryPIDL);
486  if (result->offset7C != NULL)
487  result->offset7C = ILClone(result->offset7C);
488  if (result->offset80 != NULL)
489  result->offset80 = ILClone(result->offset80);
490  if (result->offset70 != NULL)
491  result->offset70->AddRef();
492 #if 0
493  if (result->offsetC != NULL)
494  result->offsetC->Method2C();
495 #endif
496  return result;
497 }
GLuint64EXT * result
Definition: glext.h:11304
#define LMEM_FIXED
Definition: winbase.h:349
#define TRACE(s)
Definition: solgame.cpp:4
GLfloat param
Definition: glext.h:5796
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
LPITEMIDLIST WINAPI ILClone(LPCITEMIDLIST pidl)
Definition: pidl.c:228
#define NULL
Definition: types.h:112
HLOCAL NTAPI LocalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:1373

Referenced by SHOpenFolderWindow().

◆ SHCreateFromDesktop()

BOOL WINAPI SHCreateFromDesktop ( ExplorerCommandLineParseResults parseResults)

Definition at line 612 of file desktopipc.cpp.

613 {
614  TRACE("SHCreateFromDesktop\n");
615 
616  IEThreadParamBlock * parameters = SHCreateIETHREADPARAM(0, 0, 0, 0);
617  if (!parameters)
618  return FALSE;
619 
620  PCWSTR strPath = NULL;
621  if (parseResults->dwFlags & SH_EXPLORER_CMDLINE_FLAG_STRING)
622  {
623  if (parseResults->pidlPath)
624  {
625  WARN("strPath and pidlPath are both assigned. This shouldn't happen.\n");
626  }
627 
628  strPath = parseResults->strPath;
629  }
630 
631  parameters->dwFlags = parseResults->dwFlags;
632  parameters->offset8 = parseResults->nCmdShow;
633 
634  LPITEMIDLIST pidl = parseResults->pidlPath ? ILClone(parseResults->pidlPath) : NULL;
635  if (!pidl && parseResults->dwFlags & SH_EXPLORER_CMDLINE_FLAG_STRING)
636  {
637  if (parseResults->strPath && parseResults->strPath[0])
638  {
639  pidl = ILCreateFromPathW(parseResults->strPath);
640  }
641  }
642 
643  // HACK! This shouldn't happen! SHExplorerParseCmdLine needs fixing.
644  if (!pidl)
645  {
647  }
648 
649  parameters->directoryPIDL = pidl;
650 
651  // Try to find the owner of the idlist, if we aren't running /SEPARATE
652  HWND desktop = NULL;
653  if (!(parseResults->dwFlags & SH_EXPLORER_CMDLINE_FLAG_SEPARATE))
654  desktop = FindShellProxy(parameters->directoryPIDL);
655 
656  // If found, ask it to open the new window
657  if (desktop)
658  {
659  TRACE("Found desktop hwnd=%p\n", desktop);
660 
661  DWORD dwProcessId;
662 
663  GetWindowThreadProcessId(desktop, &dwProcessId);
664  AllowSetForegroundWindow(dwProcessId);
665 
666  HANDLE hShared = MakeSharedPacket(parameters, strPath, dwProcessId);
667  if (hShared)
668  {
669  TRACE("Sending open message...\n");
670 
671  PostMessageW(desktop, WM_EXPLORER_OPEN_NEW_WINDOW, 0, (LPARAM) hShared);
672  }
673 
674  SHDestroyIETHREADPARAM(parameters);
675  return TRUE;
676  }
677 
678  TRACE("Desktop not found or separate flag requested.\n");
679 
680  // Else, start our own message loop!
682  CProxyDesktop * proxy = new CProxyDesktop(parameters);
683  if (proxy)
684  {
685  g_hwndProxyDesktop = proxy->Create(0);
686 
687  LONG refCount;
689  if (SHCreateThreadRef(&refCount, &thread) >= 0)
690  {
692  if (strPath)
693  parameters->directoryPIDL = ILCreateFromPath(strPath);
694  SHOpenFolderWindow(parameters);
695  parameters = NULL;
696  thread.Release();
697  }
698 
699  MSG Msg;
700  while (GetMessageW(&Msg, 0, 0, 0) && refCount)
701  {
704  }
705 
707 
708  delete proxy;
709  }
710 
711  if (SUCCEEDED(hr))
712  CoUninitialize();
713 
714  SHDestroyIETHREADPARAM(parameters);
715 
716  return TRUE;
717 }
HRESULT WINAPI SHOpenFolderWindow(PIE_THREAD_PARAM_BLOCK parameters)
Definition: desktopipc.cpp:548
const uint16_t * PCWSTR
Definition: typedefs.h:57
BOOL WINAPI TranslateMessage(_In_ const MSG *)
int proxy
Definition: main.c:67
HRESULT hr
Definition: shlfolder.c:183
HRESULT WINAPI SHCreateThreadRef(LONG *lprefcount, IUnknown **lppUnknown)
Definition: thread.c:198
#define TRUE
Definition: types.h:120
HANDLE MakeSharedPacket(IEThreadParamBlock *threadParams, LPCWSTR strPath, int dwProcessId)
Definition: desktopipc.cpp:102
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1827
#define WARN(fmt,...)
Definition: debug.h:112
HWND FindShellProxy(LPITEMIDLIST pidl)
Definition: desktopipc.cpp:69
BOOL WINAPI AllowSetForegroundWindow(DWORD dwProcessId)
Definition: window.c:49
BOOL WINAPI DestroyWindow(_In_ HWND)
#define ILCreateFromPath
Definition: shlobj.h:2323
struct @1620 Msg[]
#define FALSE
Definition: types.h:117
LRESULT WINAPI DispatchMessageW(_In_ const MSG *)
long LONG
Definition: pedump.c:60
if SUCCEEDED(hr)
DWORD WINAPI GetWindowThreadProcessId(HWND, PDWORD)
LONG_PTR LPARAM
Definition: windef.h:208
#define TRACE(s)
Definition: solgame.cpp:4
LONG HRESULT
Definition: typedefs.h:79
nsrefcnt Release()
unsigned long DWORD
Definition: ntddk_ex.h:95
static HANDLE thread
Definition: service.c:33
HWND g_hwndProxyDesktop
Definition: desktopipc.cpp:8
IEThreadParamBlock *WINAPI SHCreateIETHREADPARAM(long param8, long paramC, IUnknown *param10, IUnknown *param14)
Definition: desktopipc.cpp:450
void WINAPI SHDestroyIETHREADPARAM(IEThreadParamBlock *param)
Definition: desktopipc.cpp:502
#define SH_EXPLORER_CMDLINE_FLAG_STRING
void WINAPI DECLSPEC_HOTPATCH CoUninitialize(void)
Definition: compobj.c:2067
LPITEMIDLIST WINAPI ILClone(LPCITEMIDLIST pidl)
Definition: pidl.c:228
#define NULL
Definition: types.h:112
VOID WINAPI SHSetInstanceExplorer(LPUNKNOWN lpUnknown)
Definition: shellord.c:1507
BOOL WINAPI GetMessageW(_Out_ LPMSG, _In_opt_ HWND, _In_ UINT, _In_ UINT)
#define WM_EXPLORER_OPEN_NEW_WINDOW
HRESULT WINAPI CoInitialize(LPVOID lpReserved)
Definition: compobj.c:1964
#define CSIDL_PERSONAL
Definition: shlobj.h:2017
BOOL WINAPI PostMessageW(_In_opt_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
HRESULT WINAPI SHGetFolderLocation(HWND hwndOwner, int nFolder, HANDLE hToken, DWORD dwReserved, LPITEMIDLIST *ppidl)
Definition: shellpath.c:2741
LPITEMIDLIST WINAPI ILCreateFromPathW(LPCWSTR path)
Definition: pidl.c:982
ITEMIDLIST UNALIGNED * LPITEMIDLIST
Definition: shtypes.idl:41
#define SH_EXPLORER_CMDLINE_FLAG_SEPARATE
LPITEMIDLIST directoryPIDL

Referenced by _tmain(), and StartWithCommandLine().

◆ SHCreateIETHREADPARAM()

IEThreadParamBlock* WINAPI SHCreateIETHREADPARAM ( long  param8,
long  paramC,
IUnknown param10,
IUnknown param14 
)

Definition at line 450 of file desktopipc.cpp.

452 {
454 
455  TRACE("SHCreateIETHREADPARAM\n");
456 
458  if (result == NULL)
459  return NULL;
460  result->offset0 = param8;
461  result->offset8 = paramC;
462  result->offsetC = param10;
463  if (param10 != NULL)
464  param10->AddRef();
465  result->offset14 = param14;
466  if (param14 != NULL)
467  param14->AddRef();
468  return result;
469 }
GLuint64EXT * result
Definition: glext.h:11304
#define TRACE(s)
Definition: solgame.cpp:4
#define LMEM_ZEROINIT
Definition: winbase.h:356
ULONG AddRef()
#define NULL
Definition: types.h:112
HLOCAL NTAPI LocalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:1373

Referenced by ParseSharedPacket(), SHCreateFromDesktop(), and SHOpenNewFrame().

◆ SHDestroyIETHREADPARAM()

void WINAPI SHDestroyIETHREADPARAM ( IEThreadParamBlock param)

Definition at line 502 of file desktopipc.cpp.

503 {
504  TRACE("SHDestroyIETHREADPARAM\n");
505 
506  if (param == NULL)
507  return;
508  if (param->directoryPIDL != NULL)
509  ILFree(param->directoryPIDL);
510  if (param->offset7C != NULL)
511  ILFree(param->offset7C);
512  if ((param->dwFlags & 0x80000) == 0 && param->offset80 != NULL)
513  ILFree(param->offset80);
514  if (param->offset14 != NULL)
515  param->offset14->Release();
516  if (param->offset70 != NULL)
517  param->offset70->Release();
518  if (param->offset78 != NULL)
519  param->offset78->Release();
520  if (param->offsetC != NULL)
521  param->offsetC->Release();
522  if (param->offsetF8 != NULL)
523  param->offsetF8->Release();
524  LocalFree(param);
525 }
void WINAPI ILFree(LPITEMIDLIST pidl)
Definition: pidl.c:925
#define TRACE(s)
Definition: solgame.cpp:4
GLfloat param
Definition: glext.h:5796
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
#define NULL
Definition: types.h:112

Referenced by BrowserThreadProc(), ParseSharedPacket(), SHCreateFromDesktop(), SHOnCWMCommandLine(), SHOpenFolderWindow(), and SHOpenNewFrame().

◆ SHOnCWMCommandLine()

BOOL WINAPI SHOnCWMCommandLine ( HANDLE  hSharedInfo)

Definition at line 530 of file desktopipc.cpp.

531 {
532  TRACE("SHOnCWMCommandLine\n");
533 
535 
536  if (params)
537  return SHOpenFolderWindow(params);
538 
540 
541  return FALSE;
542 }
HRESULT WINAPI SHOpenFolderWindow(PIE_THREAD_PARAM_BLOCK parameters)
Definition: desktopipc.cpp:548
PIE_THREAD_PARAM_BLOCK ParseSharedPacket(HANDLE hData)
Definition: desktopipc.cpp:236
#define FALSE
Definition: types.h:117
GLenum const GLfloat * params
Definition: glext.h:5645
#define TRACE(s)
Definition: solgame.cpp:4
void WINAPI SHDestroyIETHREADPARAM(IEThreadParamBlock *param)
Definition: desktopipc.cpp:502

Referenced by CProxyDesktop::OnOpenNewWindow(), and CDesktopBrowser::OnOpenNewWindow().

◆ SHOpenFolderWindow()

HRESULT WINAPI SHOpenFolderWindow ( PIE_THREAD_PARAM_BLOCK  parameters)

Definition at line 548 of file desktopipc.cpp.

549 {
550  HANDLE threadHandle;
551  DWORD threadID;
552 
553  // Only try to convert the pidl when it is going to be printed
554  if (TRACE_ON(browseui))
555  {
556  WCHAR debugStr[MAX_PATH + 2] = { 0 };
557  if (!ILGetDisplayName(parameters->directoryPIDL, debugStr))
558  {
559  debugStr[0] = UNICODE_NULL;
560  }
561  TRACE("SHOpenFolderWindow %p(%S)\n", parameters->directoryPIDL, debugStr);
562  }
563 
564  PIE_THREAD_PARAM_BLOCK paramsCopy = SHCloneIETHREADPARAM(parameters);
565 
566  SHGetInstanceExplorer(&(paramsCopy->offsetF8));
567  threadHandle = CreateThread(NULL, 0x10000, BrowserThreadProc, paramsCopy, 0, &threadID);
568  if (threadHandle != NULL)
569  {
570  CloseHandle(threadHandle);
571  return S_OK;
572  }
573  SHDestroyIETHREADPARAM(paramsCopy);
574  return E_FAIL;
575 }
IEThreadParamBlock *WINAPI SHCloneIETHREADPARAM(IEThreadParamBlock *param)
Definition: desktopipc.cpp:474
#define CloseHandle
Definition: compat.h:598
HRESULT WINAPI SHGetInstanceExplorer(IUnknown **lpUnknown)
Definition: shellord.c:1517
#define E_FAIL
Definition: ddrawi.h:102
#define UNICODE_NULL
BOOL WINAPI ILGetDisplayName(LPCITEMIDLIST pidl, LPVOID path)
Definition: pidl.c:174
HANDLE WINAPI DECLSPEC_HOTPATCH CreateThread(IN LPSECURITY_ATTRIBUTES lpThreadAttributes, IN DWORD dwStackSize, IN LPTHREAD_START_ROUTINE lpStartAddress, IN LPVOID lpParameter, IN DWORD dwCreationFlags, OUT LPDWORD lpThreadId)
Definition: thread.c:136
#define TRACE(s)
Definition: solgame.cpp:4
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:34
unsigned long DWORD
Definition: ntddk_ex.h:95
void WINAPI SHDestroyIETHREADPARAM(IEThreadParamBlock *param)
Definition: desktopipc.cpp:502
#define S_OK
Definition: intsafe.h:51
#define NULL
Definition: types.h:112
static DWORD WINAPI BrowserThreadProc(LPVOID lpThreadParameter)
Definition: desktopipc.cpp:428
#define TRACE_ON(x)
Definition: compat.h:75
LPITEMIDLIST directoryPIDL

Referenced by SHCreateFromDesktop(), SHOnCWMCommandLine(), and SHOpenNewFrame().

◆ SHOpenNewFrame()

HRESULT WINAPI SHOpenNewFrame ( LPITEMIDLIST  pidl,
IUnknown paramC,
long  param10,
DWORD  dwFlags 
)

Definition at line 584 of file desktopipc.cpp.

585 {
586  IEThreadParamBlock *parameters;
587 
588  TRACE("SHOpenNewFrame\n");
589 
590  parameters = SHCreateIETHREADPARAM(0, 1, paramC, NULL);
591  if (parameters == NULL)
592  {
593  ILFree(pidl);
594  return E_OUTOFMEMORY;
595  }
596  if (paramC != NULL)
597  parameters->offset10 = param10;
598  parameters->directoryPIDL = pidl;
599  parameters->dwFlags = dwFlags;
600 
601  HRESULT hr = SHOpenFolderWindow(parameters);
602 
603  SHDestroyIETHREADPARAM(parameters);
604 
605  return hr;
606 }
HRESULT WINAPI SHOpenFolderWindow(PIE_THREAD_PARAM_BLOCK parameters)
Definition: desktopipc.cpp:548
void WINAPI ILFree(LPITEMIDLIST pidl)
Definition: pidl.c:925
HRESULT hr
Definition: shlfolder.c:183
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define TRACE(s)
Definition: solgame.cpp:4
LONG HRESULT
Definition: typedefs.h:79
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
IEThreadParamBlock *WINAPI SHCreateIETHREADPARAM(long param8, long paramC, IUnknown *param10, IUnknown *param14)
Definition: desktopipc.cpp:450
void WINAPI SHDestroyIETHREADPARAM(IEThreadParamBlock *param)
Definition: desktopipc.cpp:502
#define NULL
Definition: types.h:112
LPITEMIDLIST directoryPIDL

Referenced by CDesktopBrowser::BrowseObject(), DDE_OnViewFolder(), and DDW_OnExploreFolder().

Variable Documentation

◆ g_hwndProxyDesktop

HWND g_hwndProxyDesktop = NULL

Definition at line 8 of file desktopipc.cpp.

Referenced by FindShellProxy(), and SHCreateFromDesktop().

◆ g_SeparateFolders

BOOL g_SeparateFolders = FALSE

Definition at line 7 of file desktopipc.cpp.

Referenced by FindShellProxy().