From: Amine Khaldi Date: Sun, 5 Mar 2017 20:57:57 +0000 (+0000) Subject: [COMDLG32_WINETEST] Sync with Wine Staging 2.2. CORE-12823 X-Git-Tag: ReactOS-0.4.5~330 X-Git-Url: https://git.reactos.org/?p=reactos.git;a=commitdiff_plain;h=74568a6e4d0b0a2431c5310ab18632cac5fba288 [COMDLG32_WINETEST] Sync with Wine Staging 2.2. CORE-12823 svn path=/trunk/; revision=74093 --- diff --git a/rostests/winetests/comdlg32/filedlg.c b/rostests/winetests/comdlg32/filedlg.c index 69dd3ff9fb7..e779cd55367 100644 --- a/rostests/winetests/comdlg32/filedlg.c +++ b/rostests/winetests/comdlg32/filedlg.c @@ -37,6 +37,9 @@ #define COBJMACROS #include +#include +#include + /* ##### */ static BOOL resizesupported = TRUE; @@ -1274,6 +1277,73 @@ 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) +{ + HRESULT hr; + + hr = OleInitialize(NULL); + ok(hr == S_FALSE, "OleInitialize() returned %#x\n", hr); + OleUninitialize(); + + if (msg == WM_NOTIFY) + PostMessageA(GetParent(dlg), 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) + { + /* OleInitialize() creates a window for the main apartment. Since + * Vista OleInitialize() is called before the file dialog is + * created. SimCity 2000 expects that the first window created + * after GetOpenFileA() is a file dialog window. Mark Vista+ + * behavior as broken. */ + hr = OleInitialize(NULL); + ok((first_dlg ? hr == S_OK : hr == S_FALSE) + || broken(first_dlg && hr == S_FALSE), + "OleInitialize() returned %#x (first dialog %#x)\n", hr, first_dlg); + 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(); @@ -1288,4 +1358,5 @@ START_TEST(filedlg) test_extension(); test_null_filename(); test_directory_filename(); + test_ole_initialization(); }