Skip to content

Commit

Permalink
[SHELL32] Clone properties IDataObject for unlimited lifetime (reacto…
Browse files Browse the repository at this point in the history
…s#7601)

Because SHOpenPropSheetW() is modal, there is no way for us to keep COM
alive on the original thread until the dialog completes, so a cloned
data object is used instead so that the property sheet handlers may access
the object even after ShellExecute() has returned (this is only relevant
for callers like Taskmgr that does not initialize COM even though MSDN
says they should).

Addendum to afc130f (PR reactos#7571). CORE-19933
  • Loading branch information
whindsaks authored Jan 8, 2025
1 parent 1dfba2a commit 03ee075
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
15 changes: 9 additions & 6 deletions dll/win32/shell32/dialogs/item_prop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ struct ShellPropSheetDialog
HKEY *hKeys, UINT *cKeys);

static HRESULT Show(const CLSID *pClsidDefault, IDataObject *pDO,
PFNINITIALIZE InitFunc, LPCWSTR InitString, HANDLE hEvent = NULL)
PFNINITIALIZE InitFunc, LPCWSTR InitString)
{
HRESULT hr;
CRegKeyHandleArray keys;
Expand All @@ -36,8 +36,6 @@ struct ShellPropSheetDialog
WCHAR szCaption[MAX_PATH], *pszCaption = NULL;
if (SUCCEEDED(SHELL_GetCaptionFromDataObject(pDO, szCaption, _countof(szCaption))))
pszCaption = szCaption;
if (hEvent)
SetEvent(hEvent);
hr = SHOpenPropSheetW(pszCaption, keys, keys, pClsidDefault, pDO, NULL, NULL) ? S_OK : E_FAIL;
return hr;
}
Expand Down Expand Up @@ -96,7 +94,8 @@ struct ShellPropSheetDialog
if (hEvent)
{
DWORD index;
// Pump COM messages until InitFunc is done (for CORE-19933)
// Pump COM messages until the thread can create its own IDataObject (for CORE-19933).
// SHOpenPropSheetW is modal and we cannot wait for it to complete.
CoWaitForMultipleHandles(COWAIT_DEFAULT, INFINITE, 1, &hEvent, &index);
CloseHandle(hEvent);
}
Expand All @@ -111,10 +110,14 @@ struct ShellPropSheetDialog
static DWORD CALLBACK ShowPropertiesThread(LPVOID Param)
{
DATA *pData = (DATA*)Param;
CComPtr<IDataObject> pDO;
CComPtr<IDataObject> pDO, pLocalDO;
if (pData->pObjStream)
CoGetInterfaceAndReleaseStream(pData->pObjStream, IID_PPV_ARG(IDataObject, &pDO));
Show(pData->pClsidDefault, pDO, pData->InitFunc, pData->InitString, pData->hEvent);
if (pDO && SUCCEEDED(SHELL_CloneDataObject(pDO, &pLocalDO)))
pDO = pLocalDO;
if (pData->hEvent)
SetEvent(pData->hEvent);
Show(pData->pClsidDefault, pDO, pData->InitFunc, pData->InitString);
FreeData(pData);
return 0;
}
Expand Down
1 change: 1 addition & 0 deletions dll/win32/shell32/precomp.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ HRESULT SHILAppend(_Inout_ LPITEMIDLIST pidl, _Inout_ LPITEMIDLIST *ppidl);

PIDLIST_ABSOLUTE SHELL_CIDA_ILCloneFull(_In_ const CIDA *pCIDA, _In_ UINT Index);
PIDLIST_ABSOLUTE SHELL_DataObject_ILCloneFullItem(_In_ IDataObject *pDO, _In_ UINT Index);
HRESULT SHELL_CloneDataObject(_In_ IDataObject *pDO, _Out_ IDataObject **ppDO);

EXTERN_C HRESULT
IUnknown_InitializeCommand(
Expand Down
19 changes: 19 additions & 0 deletions dll/win32/shell32/shldataobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,22 @@ PIDLIST_ABSOLUTE SHELL_DataObject_ILCloneFullItem(_In_ IDataObject *pDO, _In_ UI
CDataObjectHIDA cida(pDO);
return SUCCEEDED(cida.hr()) ? SHELL_CIDA_ILCloneFull(cida, Index) : NULL;
}

HRESULT SHELL_CloneDataObject(_In_ IDataObject *pDO, _Out_ IDataObject **ppDO)
{
*ppDO = NULL;
CDataObjectHIDA cida(pDO);
HRESULT hr = cida.hr();
if (SUCCEEDED(hr))
{
PCUITEMID_CHILD items = HIDA_GetPIDLItem(cida, 0);
hr = SHCreateFileDataObject(HIDA_GetPIDLFolder(cida), cida->cidl, &items, NULL, ppDO);
if (SUCCEEDED(hr))
{
POINT pt;
if (SUCCEEDED(DataObject_GetOffset(pDO, &pt)))
DataObject_SetOffset(*ppDO, &pt);
}
}
return hr;
}

0 comments on commit 03ee075

Please sign in to comment.