[PATCH 1/2] comdlg32/tests: Add test for OLE initialization in file dialogs.

Józef Kucia jkucia at codeweavers.com
Wed Jan 25 07:51:27 CST 2017


Signed-off-by: Józef Kucia <jkucia at codeweavers.com>
---
 dlls/comdlg32/tests/filedlg.c | 67 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 67 insertions(+)

diff --git a/dlls/comdlg32/tests/filedlg.c b/dlls/comdlg32/tests/filedlg.c
index 9270b66..80c9ec1 100644
--- a/dlls/comdlg32/tests/filedlg.c
+++ b/dlls/comdlg32/tests/filedlg.c
@@ -1266,6 +1266,72 @@ static void test_directory_filename(void)
     todo_wine ok(!ret, "GetOpenFileNameW returned %#x\n", ret);
 }
 
+static UINT_PTR WINAPI test_ole_init_wndproc(HWND dlg, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+    HWND parent = GetParent(dlg);
+    HRESULT hr;
+
+    if (msg == WM_NOTIFY)
+    {
+        hr = OleInitialize(NULL);
+        ok(hr == S_FALSE, "OleInitialize() returned %#x\n", hr);
+        OleUninitialize();
+
+        PostMessageA(parent, WM_COMMAND, IDCANCEL, 0);
+    }
+    return FALSE;
+}
+
+static LRESULT CALLBACK hook_proc(int code, WPARAM wp, LPARAM lp)
+{
+    static BOOL first_dlg = TRUE;
+    HRESULT hr;
+
+    if (code == HCBT_CREATEWND)
+    {
+        CBT_CREATEWNDW *c = (CBT_CREATEWNDW *)lp;
+
+        if (c->lpcs->lpszClass == (LPWSTR)WC_DIALOG)
+        {
+            /* Before Vista, OleInitialize() is called after the file dialog is
+             * created. */
+            hr = OleInitialize(NULL);
+            ok(hr == S_FALSE || broken(first_dlg && hr == S_OK),
+                    "OleInitialize() returned %#x\n", hr);
+            OleUninitialize();
+            first_dlg = FALSE;
+        }
+    }
+
+    return CallNextHookEx(NULL, code, wp, lp);
+}
+
+static void test_ole_initialization(void)
+{
+    char file[MAX_PATH] = {0};
+    OPENFILENAMEA ofn = {0};
+    HRESULT hr;
+    HHOOK hook;
+    BOOL ret;
+
+    hook = SetWindowsHookExW(WH_CBT, hook_proc, NULL, GetCurrentThreadId());
+
+    ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400A;
+    ofn.lpstrFile = file;
+    ofn.nMaxFile = MAX_PATH;
+    ofn.lpfnHook = test_ole_init_wndproc;
+    ofn.Flags = OFN_ENABLEHOOK | OFN_EXPLORER;
+    ofn.hInstance = GetModuleHandleA(NULL);
+    ret = GetOpenFileNameA(&ofn);
+    ok(!ret, "GetOpenFileNameA returned %#x\n", ret);
+
+    hr = OleInitialize(NULL);
+    ok(hr == S_OK, "OleInitialize() returned %#x\n", hr);
+    OleUninitialize();
+
+    UnhookWindowsHookEx(hook);
+}
+
 START_TEST(filedlg)
 {
     test_DialogCancel();
@@ -1280,4 +1346,5 @@ START_TEST(filedlg)
     test_extension();
     test_null_filename();
     test_directory_filename();
+    test_ole_initialization();
 }
-- 
2.10.2




More information about the wine-patches mailing list