diff --git a/reactos/dll/win32/browseui/browseui.h b/reactos/dll/win32/browseui/browseui.h index 4a07238b1d0..37faa9a01f6 100644 --- a/reactos/dll/win32/browseui/browseui.h +++ b/reactos/dll/win32/browseui/browseui.h @@ -10,6 +10,7 @@ #define USE_CUSTOM_INTERNETTOOLBAR 1 /* Constructors for the classes that are not exported */ +HRESULT CShellBrowser_CreateInstance(LPITEMIDLIST pidl, DWORD dwFlags, REFIID riid, void **ppv); HRESULT CTravelLog_CreateInstance(REFIID riid, void **ppv); HRESULT CBaseBar_CreateInstance(REFIID riid, void **ppv, BOOL vertical); HRESULT CBaseBarSite_CreateInstance(REFIID riid, void **ppv, BOOL bVertical); diff --git a/reactos/dll/win32/browseui/desktopipc.cpp b/reactos/dll/win32/browseui/desktopipc.cpp index 5874b785bb7..e97d447c93d 100644 --- a/reactos/dll/win32/browseui/desktopipc.cpp +++ b/reactos/dll/win32/browseui/desktopipc.cpp @@ -28,8 +28,6 @@ struct HNFBlock UINT pathLength; }; -extern DWORD WINAPI BrowserThreadProc(LPVOID lpThreadParameter); - class CProxyDesktop : public CComObjectRootEx, public CWindowImpl < CProxyDesktop, CWindow, CFrameWinTraits > @@ -345,6 +343,70 @@ cleanup0: return params; } + +static HRESULT ExplorerMessageLoop(IEThreadParamBlock * parameters) +{ + CComPtr browser; + HRESULT hResult; + MSG Msg; + BOOL Ret; + + // Tell the thread ref we are using it. + if (parameters && parameters->offsetF8) + parameters->offsetF8->AddRef(); + + hResult = CShellBrowser_CreateInstance(parameters->directoryPIDL, parameters->dwFlags, IID_PPV_ARG(IBrowserService2, &browser)); + if (FAILED_UNEXPECTEDLY(hResult)) + return hResult; + + while ((Ret = GetMessage(&Msg, NULL, 0, 0)) != 0) + { + if (Ret == -1) + { + // Error: continue or exit? + break; + } + + if (Msg.message == WM_QUIT) + break; + + if (browser->v_MayTranslateAccelerator(&Msg) != S_OK) + { + TranslateMessage(&Msg); + DispatchMessage(&Msg); + } + } + + int nrc = browser->Release(); + if (nrc > 0) + { + DbgPrint("WARNING: There are %d references to the CShellBrowser active or leaked.\n", nrc); + } + + browser.Detach(); + + // Tell the thread ref we are not using it anymore. + if (parameters && parameters->offsetF8) + parameters->offsetF8->Release(); + + return hResult; +} + +static DWORD WINAPI BrowserThreadProc(LPVOID lpThreadParameter) +{ + IEThreadParamBlock * parameters = (IEThreadParamBlock *) lpThreadParameter; + + OleInitialize(NULL); + ExplorerMessageLoop(parameters); + + /* Destroying the parameters releases the thread reference */ + SHDestroyIETHREADPARAM(parameters); + + OleUninitialize(); + + return 0; +} + /************************************************************************* * SHCreateIETHREADPARAM [BROWSEUI.123] */ diff --git a/reactos/dll/win32/browseui/shellbrowser.cpp b/reactos/dll/win32/browseui/shellbrowser.cpp index de36b27c2e2..3f7c0fae0c8 100644 --- a/reactos/dll/win32/browseui/shellbrowser.cpp +++ b/reactos/dll/win32/browseui/shellbrowser.cpp @@ -309,7 +309,7 @@ public: CShellBrowser(); ~CShellBrowser(); - HRESULT Initialize(LPITEMIDLIST pidl, long b, long c, long d); + HRESULT Initialize(LPITEMIDLIST pidl, DWORD dwFlags); public: HRESULT BrowseToPIDL(LPCITEMIDLIST pidl, long flags); HRESULT BrowseToPath(IShellFolder *newShellFolder, LPCITEMIDLIST absolutePIDL, @@ -706,7 +706,7 @@ CShellBrowser::~CShellBrowser() DSA_Destroy(menuDsa); } -HRESULT CShellBrowser::Initialize(LPITEMIDLIST pidl, long b, long c, long d) +HRESULT CShellBrowser::Initialize(LPITEMIDLIST pidl, DWORD dwFlags) { CComPtr persistStreamInit; HRESULT hResult; @@ -3697,72 +3697,7 @@ LRESULT CShellBrowser::RelayCommands(UINT uMsg, WPARAM wParam, LPARAM lParam, BO return 0; } -static HRESULT ExplorerMessageLoop(IEThreadParamBlock * parameters) +HRESULT CShellBrowser_CreateInstance(LPITEMIDLIST pidl, DWORD dwFlags, REFIID riid, void **ppv) { - CComPtr theCabinet; - HRESULT hResult; - MSG Msg; - BOOL Ret; - - // Tell the thread ref we are using it. - if (parameters && parameters->offsetF8) - parameters->offsetF8->AddRef(); - - ATLTRY(theCabinet = new CComObject); - if (theCabinet == NULL) - { - return E_OUTOFMEMORY; - } - - hResult = theCabinet->Initialize(parameters->directoryPIDL, 0, 0, 0); - if (FAILED_UNEXPECTEDLY(hResult)) - return E_OUTOFMEMORY; - - while ((Ret = GetMessage(&Msg, NULL, 0, 0)) != 0) - { - if (Ret == -1) - { - // Error: continue or exit? - break; - } - - if (Msg.message == WM_QUIT) - break; - - if (theCabinet->v_MayTranslateAccelerator(&Msg) != S_OK) - { - TranslateMessage(&Msg); - DispatchMessage(&Msg); - } - } - - int nrc = theCabinet->Release(); - if (nrc > 0) - { - DbgPrint("WARNING: There are %d references to the CShellBrowser active or leaked.\n", nrc); - } - - theCabinet.Detach(); - - // Tell the thread ref we are not using it anymore. - if (parameters && parameters->offsetF8) - parameters->offsetF8->Release(); - - return hResult; -} - -DWORD WINAPI BrowserThreadProc(LPVOID lpThreadParameter) -{ - HRESULT hr; - IEThreadParamBlock * parameters = (IEThreadParamBlock *) lpThreadParameter; - - OleInitialize(NULL); - - ATLTRY(hr = ExplorerMessageLoop(parameters)); - - OleUninitialize(); - - SHDestroyIETHREADPARAM(parameters); - - return hr; + return ShellObjectCreatorInit(pidl, dwFlags, riid, ppv); }