[BROWSEUI]
authorGiannis Adamopoulos <gadamopoulos@reactos.org>
Fri, 4 Nov 2016 23:56:02 +0000 (23:56 +0000)
committerGiannis Adamopoulos <gadamopoulos@reactos.org>
Fri, 4 Nov 2016 23:56:02 +0000 (23:56 +0000)
- CShellBrowser: Add a standard ShellObjectCreatorInit constructor and make its initializer take a pidl and flags.
- Move BrowserThreadProc to desktopipc.cpp where the lifetime of the browser thread will be managed.

svn path=/trunk/; revision=73129

reactos/dll/win32/browseui/browseui.h
reactos/dll/win32/browseui/desktopipc.cpp
reactos/dll/win32/browseui/shellbrowser.cpp

index 4a07238..37faa9a 100644 (file)
@@ -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);
index 5874b78..e97d447 100644 (file)
@@ -28,8 +28,6 @@ struct HNFBlock
     UINT                pathLength;
 };
 
-extern DWORD WINAPI BrowserThreadProc(LPVOID lpThreadParameter);
-
 class CProxyDesktop :
     public CComObjectRootEx<CComMultiThreadModelNoCS>,
     public CWindowImpl < CProxyDesktop, CWindow, CFrameWinTraits >
@@ -345,6 +343,70 @@ cleanup0:
     return params;
 }
 
+
+static HRESULT ExplorerMessageLoop(IEThreadParamBlock * parameters)
+{
+    CComPtr<IBrowserService2> 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]
 */
index de36b27..3f7c0fa 100644 (file)
@@ -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<IPersistStreamInit>             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<CShellBrowser>    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<CShellBrowser>);
-    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<CShellBrowser>(pidl, dwFlags, riid, ppv);
 }