[COMDLG32_WINETEST] Sync with Wine Staging 1.9.4. CORE-10912
[reactos.git] / rostests / winetests / comdlg32 / filedlg.c
index 71f7d2a..f4fd464 100644 (file)
  *
  */
 
-#include <windows.h>
+//#include <windows.h>
+
+#define WIN32_NO_STATUS
+#define _INC_WINDOWS
+#define COM_NO_WINDOWS_H
+
 #include <wine/test.h>
 
-#include "initguid.h"
-#include "shlguid.h"
+#include <wingdi.h>
+#include <objbase.h>
+#include <cderr.h>
+#include <dlgs.h>
+#include <commdlg.h>
+
+#include <shlguid.h>
 #define COBJMACROS
-#include "shobjidl.h"
+#include <shobjidl.h>
 
 /* ##### */
 
-static int resizesupported = TRUE;
+static BOOL resizesupported = TRUE;
 
 static void toolbarcheck( HWND hDlg)
 {
@@ -42,14 +52,14 @@ static void toolbarcheck( HWND hDlg)
 
     for( ctrl = GetWindow( hDlg, GW_CHILD);
             ctrl ; ctrl = GetWindow( ctrl, GW_HWNDNEXT)) {
-        GetClassName( ctrl, classname, 10);
+        GetClassNameA( ctrl, classname, 10);
         classname[7] = '\0';
         if( !strcmp( classname, "Toolbar")) break;
     }
     ok( ctrl != NULL, "could not get the toolbar control\n");
-    ret = SendMessage( ctrl, TB_ADDSTRING, 0, (LPARAM)"winetestwinetest\0\0");
+    ret = SendMessageA( ctrl, TB_ADDSTRINGA, 0, (LPARAM)"winetestwinetest\0\0");
     ok( ret == 0, "addstring returned %d (expected 0)\n", ret);
-    maxtextrows = SendMessage( ctrl, TB_GETTEXTROWS, 0, 0);
+    maxtextrows = SendMessageA( ctrl, TB_GETTEXTROWS, 0, 0);
     ok( maxtextrows == 0 || broken(maxtextrows == 1),  /* Win2k and below */
         "Get(Max)TextRows returned %d (expected 0)\n", maxtextrows);
 }
@@ -64,14 +74,14 @@ static UINT_PTR CALLBACK OFNHookProc( HWND hDlg, UINT msg, WPARAM wParam, LPARAM
         nmh = (LPNMHDR) lParam;
         if( nmh->code == CDN_INITDONE)
         {
-            PostMessage( GetParent(hDlg), WM_COMMAND, IDCANCEL, FALSE);
+            PostMessageA( GetParent(hDlg), WM_COMMAND, IDCANCEL, FALSE);
         } else if (nmh->code == CDN_FOLDERCHANGE )
         {
             char buf[1024];
             int ret;
 
             memset(buf, 0x66, sizeof(buf));
-            ret = SendMessage( GetParent(hDlg), CDM_GETFOLDERIDLIST, 5, (LPARAM)buf);
+            ret = SendMessageA( GetParent(hDlg), CDM_GETFOLDERIDLIST, 5, (LPARAM)buf);
             ok(ret > 0, "CMD_GETFOLDERIDLIST not implemented\n");
             if (ret > 5)
                 ok(buf[0] == 0x66 && buf[1] == 0x66, "CMD_GETFOLDERIDLIST: The buffer was touched on failure\n");
@@ -90,11 +100,11 @@ static void test_DialogCancel(void)
     char szFileName[MAX_PATH] = "";
     char szInitialDir[MAX_PATH];
 
-    GetWindowsDirectory(szInitialDir, MAX_PATH);
+    GetWindowsDirectoryA(szInitialDir, MAX_PATH);
 
     ZeroMemory(&ofn, sizeof(ofn));
 
-    ofn.lStructSize = sizeof(ofn);
+    ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400A;
     ofn.hwndOwner = NULL;
     ofn.lpstrFilter = "Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0";
     ofn.lpstrFile = szFileName;
@@ -109,7 +119,7 @@ static void test_DialogCancel(void)
        "expected CDERR_INITIALIZATION, got %d\n", CommDlgExtendedError());
 
     result = GetOpenFileNameA(&ofn);
-    ok(0 == result, "expected 0, got %d\n", result);
+    ok(FALSE == result, "expected FALSE, got %d\n", result);
     ok(0 == CommDlgExtendedError(), "expected 0, got %d\n",
        CommDlgExtendedError());
 
@@ -118,7 +128,7 @@ static void test_DialogCancel(void)
        "expected CDERR_INITIALIZATION, got %d\n", CommDlgExtendedError());
 
     result = GetSaveFileNameA(&ofn);
-    ok(0 == result, "expected 0, got %d\n", result);
+    ok(FALSE == result, "expected FALSE, got %d\n", result);
     ok(0 == CommDlgExtendedError(), "expected 0, got %d\n",
        CommDlgExtendedError());
 
@@ -141,10 +151,8 @@ static void test_DialogCancel(void)
         win_skip("GetOpenFileNameW is not implemented\n");
     else
     {
-        ok(0 == result, "expected 0, got %d\n", result);
-        ok(0 == CommDlgExtendedError() ||
-           broken(CDERR_INITIALIZATION == CommDlgExtendedError()), /* win9x */
-           "expected 0, got %d\n", CommDlgExtendedError());
+        ok(FALSE == result, "expected FALSE, got %d\n", result);
+        ok(0 == CommDlgExtendedError(), "expected 0, got %d\n", CommDlgExtendedError());
     }
 
     SetLastError(0xdeadbeef);
@@ -153,10 +161,8 @@ static void test_DialogCancel(void)
         win_skip("GetSaveFileNameW is not implemented\n");
     else
     {
-        ok(0 == result, "expected 0, got %d\n", result);
-        ok(0 == CommDlgExtendedError() ||
-           broken(CDERR_INITIALIZATION == CommDlgExtendedError()), /* win9x */
-           "expected 0, got %d\n", CommDlgExtendedError());
+        ok(FALSE == result, "expected FALSE, got %d\n", result);
+        ok(0 == CommDlgExtendedError(), "expected 0, got %d\n", CommDlgExtendedError());
     }
 }
 
@@ -166,7 +172,7 @@ static UINT_PTR CALLBACK create_view_window2_hook(HWND dlg, UINT msg, WPARAM wPa
     {
         if (((LPNMHDR)lParam)->code == CDN_FOLDERCHANGE)
         {
-            IShellBrowser *shell_browser = (IShellBrowser *)SendMessage(GetParent(dlg), WM_USER + 7 /* WM_GETISHELLBROWSER */, 0, 0);
+            IShellBrowser *shell_browser = (IShellBrowser *)SendMessageA(GetParent(dlg), WM_USER + 7 /* WM_GETISHELLBROWSER */, 0, 0);
             IShellView *shell_view = NULL;
             IShellView2 *shell_view2 = NULL;
             SV2CVW2_PARAMS view_params;
@@ -219,7 +225,7 @@ static UINT_PTR CALLBACK create_view_window2_hook(HWND dlg, UINT msg, WPARAM wPa
             hr = IShellView2_DestroyViewWindow(shell_view2);
             ok(SUCCEEDED(hr), "DestroyViewWindow returned %#x\n", hr);
 
-            /* XP and W2K3 need this. On Win9x and W2K the call to DestroyWindow() fails and has
+            /* XP and W2K3 need this. On W2K the call to DestroyWindow() fails and has
              * no side effects. NT4 doesn't get here. (FIXME: Vista doesn't get here yet).
              */
             DestroyWindow(view_params.hwndView);
@@ -231,21 +237,20 @@ static UINT_PTR CALLBACK create_view_window2_hook(HWND dlg, UINT msg, WPARAM wPa
 
             hr = IShellView2_GetCurrentInfo(shell_view2, &folder_settings);
             ok(SUCCEEDED(hr), "GetCurrentInfo returned %#x\n", hr);
-            ok(folder_settings.ViewMode == FVM_DETAILS ||
-               broken(folder_settings.ViewMode == FVM_LIST), /* Win9x */
+            ok(folder_settings.ViewMode == FVM_DETAILS || broken(folder_settings.ViewMode == FVM_LIST), /* nt4 */
                "view mode is %d, expected FVM_DETAILS\n",
                folder_settings.ViewMode);
 
 cleanup:
             if (shell_view2) IShellView2_Release(shell_view2);
             if (shell_view) IShellView_Release(shell_view);
-            PostMessage(GetParent(dlg), WM_COMMAND, IDCANCEL, 0);
+            PostMessageA(GetParent(dlg), WM_COMMAND, IDCANCEL, 0);
         }
     }
     return 0;
 }
 
-static LONG_PTR WINAPI template_hook(HWND dlg, UINT msg, WPARAM wParam, LPARAM lParam)
+static UINT_PTR WINAPI template_hook(HWND dlg, UINT msg, WPARAM wParam, LPARAM lParam)
 {
     if (msg == WM_INITDIALOG)
     {
@@ -255,13 +260,13 @@ static LONG_PTR WINAPI template_hook(HWND dlg, UINT msg, WPARAM wParam, LPARAM l
         ok(p!=NULL, "Failed to get parent of template\n");
         cb = GetDlgItem(p,0x470);
         ok(cb!=NULL, "Failed to get filter combobox\n");
-        sel = SendMessage(cb, CB_GETCURSEL, 0, 0);
+        sel = SendMessageA(cb, CB_GETCURSEL, 0, 0);
         ok (sel != -1, "Failed to get selection from filter listbox\n");
     }
     if (msg == WM_NOTIFY)
     {
         if (((LPNMHDR)lParam)->code == CDN_FOLDERCHANGE)
-            PostMessage(GetParent(dlg), WM_COMMAND, IDCANCEL, 0);
+            PostMessageA(GetParent(dlg), WM_COMMAND, IDCANCEL, 0);
     }
     return 0;
 }
@@ -272,7 +277,7 @@ static void test_create_view_window2(void)
     char filename[1024] = {0};
     DWORD ret;
 
-    ofn.lStructSize = sizeof(ofn);
+    ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400A;
     ofn.lpstrFile = filename;
     ofn.nMaxFile = 1024;
     ofn.lpfnHook = create_view_window2_hook;
@@ -289,10 +294,10 @@ static void test_create_view_template(void)
     char filename[1024] = {0};
     DWORD ret;
 
-    ofn.lStructSize = sizeof(ofn);
+    ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400A;
     ofn.lpstrFile = filename;
     ofn.nMaxFile = 1024;
-    ofn.lpfnHook = (LPOFNHOOKPROC)template_hook;
+    ofn.lpfnHook = template_hook;
     ofn.Flags = OFN_ENABLEHOOK | OFN_EXPLORER| OFN_ENABLETEMPLATE;
     ofn.hInstance = GetModuleHandleA(NULL);
     ofn.lpTemplateName = "template1";
@@ -304,7 +309,7 @@ static void test_create_view_template(void)
 }
 
 /* test cases for resizing of the file dialog */
-struct {
+static const struct {
     DWORD flags;
     int resize_folderchange;/* change in CDN_FOLDERCHANGE handler */
     int resize_timer1;      /* change in first WM_TIMER handler */
@@ -324,11 +329,11 @@ struct {
     { 0xffffffff }
 };
 
-static LONG_PTR WINAPI resize_template_hook(HWND dlg, UINT msg, WPARAM wParam, LPARAM lParam)
+static UINT_PTR WINAPI resize_template_hook(HWND dlg, UINT msg, WPARAM wParam, LPARAM lParam)
 {
     static RECT initrc, rc;
     static int index, count;
-    static int gotSWP_bottom, gotShowWindow;
+    static BOOL gotSWP_bottom, gotShowWindow;
     HWND parent = GetParent( dlg);
     int resize;
 #define MAXNRCTRLS 30
@@ -343,16 +348,16 @@ static LONG_PTR WINAPI resize_template_hook(HWND dlg, UINT msg, WPARAM wParam, L
         {
             DWORD style;
 
-            index = ((OPENFILENAME*)lParam)->lCustData;
+            index = ((OPENFILENAMEA*)lParam)->lCustData;
             count = 0;
-            gotSWP_bottom = gotShowWindow = 0;
+            gotSWP_bottom = gotShowWindow = FALSE;
             /* test style */
-            style = GetWindowLong( parent, GWL_STYLE);
+            style = GetWindowLongA( parent, GWL_STYLE);
             if( resize_testcases[index].flags & OFN_ENABLESIZING)
                 if( !(style & WS_SIZEBOX)) {
                     win_skip( "OFN_ENABLESIZING flag not supported.\n");
                     resizesupported = FALSE;
-                    PostMessage( parent, WM_COMMAND, IDCANCEL, 0);
+                    PostMessageA( parent, WM_COMMAND, IDCANCEL, 0);
                 } else
                     ok( style & WS_SIZEBOX,
                             "testid %d: dialog should have a WS_SIZEBOX style.\n", index);
@@ -398,8 +403,7 @@ static LONG_PTR WINAPI resize_template_hook(HWND dlg, UINT msg, WPARAM wParam, L
             } else if( count == 1){
                 resize  = resize_testcases[index].resize_check;
                 GetWindowRect( parent, &rc);
-                if( resize_testcases[index].todo){
-                    todo_wine {
+                todo_wine_if( resize_testcases[index].todo){
                         ok( resize == rc.right - rc.left - initrc.right + initrc.left,
                             "testid %d size-x change %d expected %d\n", index,
                             rc.right - rc.left - initrc.right + initrc.left, resize);
@@ -407,14 +411,6 @@ static LONG_PTR WINAPI resize_template_hook(HWND dlg, UINT msg, WPARAM wParam, L
                             "testid %d size-y change %d expected %d\n", index,
                             rc.bottom - rc.top - initrc.bottom + initrc.top, resize);
                     }
-                }else{
-                    ok( resize == rc.right - rc.left - initrc.right + initrc.left,
-                        "testid %d size-x change %d expected %d\n", index,
-                        rc.right - rc.left - initrc.right + initrc.left, resize);
-                    ok( resize == rc.bottom - rc.top - initrc.bottom + initrc.top,
-                        "testid %d size-y change %d expected %d\n", index,
-                        rc.bottom - rc.top - initrc.bottom + initrc.top, resize);
-                }
                 if( resize_testcases[index].testcontrols) {
                     int i;
                     RECT rc;
@@ -433,8 +429,7 @@ static LONG_PTR WINAPI resize_template_hook(HWND dlg, UINT msg, WPARAM wParam, L
                             /* sized horizontal and moved vertical */
                             case cmb1:
                             case edt1:
-                                ok( TESTRECTS( ctrlrcs[i], rc, 0, 10, 10, 0) ||
-                                    broken(TESTRECTS( ctrlrcs[i], rc, 0, 10, 0, 0)),/*win98*/
+                                ok( TESTRECTS( ctrlrcs[i], rc, 0, 10, 10, 0),
                                     "control id %03x should have sized horizontally and moved vertically, before %d,%d-%d,%d after  %d,%d-%d,%d\n",
                                     ctrlids[i], ctrlrcs[i].left, ctrlrcs[i].top,
                                     ctrlrcs[i].right, ctrlrcs[i].bottom,
@@ -451,8 +446,7 @@ static LONG_PTR WINAPI resize_template_hook(HWND dlg, UINT msg, WPARAM wParam, L
                             /* moved horizontal and vertical */
                             case IDCANCEL:
                             case pshHelp:
-                                ok( TESTRECTS( ctrlrcs[i], rc, 10, 10, 0, 0) ||
-                                    broken(TESTRECTS( ctrlrcs[i], rc, 0, 10, 0, 0)),/*win98*/
+                                ok( TESTRECTS( ctrlrcs[i], rc, 10, 10, 0, 0),
                                     "control id %03x should have moved horizontally and vertically, before %d,%d-%d,%d after  %d,%d-%d,%d\n",
                                     ctrlids[i], ctrlrcs[i].left, ctrlrcs[i].top,
                                     ctrlrcs[i].right, ctrlrcs[i].bottom,
@@ -511,7 +505,7 @@ todo_wine
                     }
                 }
                 KillTimer( dlg, 0);
-                PostMessage( parent, WM_COMMAND, IDCANCEL, 0);
+                PostMessageA( parent, WM_COMMAND, IDCANCEL, 0);
             }
             count++;
         }
@@ -520,16 +514,16 @@ todo_wine
         {
             WINDOWPOS *pwp = (WINDOWPOS *)lParam;
             if(  !index && pwp->hwndInsertAfter == HWND_BOTTOM){
-                gotSWP_bottom = 1;
-                ok( gotShowWindow == 0, "The WM_WINDOWPOSCHANGING message came after a WM_SHOWWINDOW message\n");
+                gotSWP_bottom = TRUE;
+                ok(!gotShowWindow, "The WM_WINDOWPOSCHANGING message came after a WM_SHOWWINDOW message\n");
             }
         }
         break;
         case WM_SHOWWINDOW:
         {
             if(  !index){
-                gotShowWindow = 1;
-                ok( gotSWP_bottom == 1, "No WM_WINDOWPOSCHANGING message came before a WM_SHOWWINDOW message\n");
+                gotShowWindow = TRUE;
+                ok(gotSWP_bottom, "No WM_WINDOWPOSCHANGING message came before a WM_SHOWWINDOW message\n");
             }
         }
         break;
@@ -539,21 +533,21 @@ todo_wine
 
 static void test_resize(void)
 {
-    OPENFILENAME ofn = { sizeof(OPENFILENAME)};
+    OPENFILENAMEA ofn = { OPENFILENAME_SIZE_VERSION_400A };
     char filename[1024] = {0};
     DWORD ret;
     int i;
 
     ofn.lpstrFile = filename;
     ofn.nMaxFile = 1024;
-    ofn.lpfnHook = (LPOFNHOOKPROC) resize_template_hook;
-    ofn.hInstance = GetModuleHandle(NULL);
+    ofn.lpfnHook = resize_template_hook;
+    ofn.hInstance = GetModuleHandleA(NULL);
     ofn.lpTemplateName = "template_sz";
     for( i = 0; resize_testcases[i].flags != 0xffffffff; i++) {
         ofn.lCustData = i;
         ofn.Flags = resize_testcases[i].flags |
             OFN_ENABLEHOOK | OFN_EXPLORER| OFN_ENABLETEMPLATE | OFN_SHOWHELP ;
-        ret = GetOpenFileName(&ofn);
+        ret = GetOpenFileNameA(&ofn);
         ok(!ret, "GetOpenFileName returned %#x\n", ret);
         ret = CommDlgExtendedError();
         ok(!ret, "CommDlgExtendedError returned %#x\n", ret);
@@ -562,14 +556,16 @@ static void test_resize(void)
 
 /* test cases for control message IDOK */
 /* Show case for bug #19079 */
-static struct {
+typedef struct {
     int  retval;        /* return code of the message handler */
     BOOL setmsgresult;  /* set the result in the DWLP_MSGRESULT */
     BOOL usemsgokstr;   /* use the FILEOKSTRING message instead of WM_NOTIFY:CDN_FILEOK */
     BOOL do_subclass;   /* subclass the dialog hook procedure */
     BOOL expclose;      /* is the dialog expected to close ? */
     BOOL actclose;      /* has the dialog actually closed ? */
-} ok_testcases[] = {
+} ok_wndproc_testcase;
+
+static ok_wndproc_testcase ok_testcases[] = {
     { 0,        FALSE,  FALSE,  FALSE,  TRUE},
     { 0,         TRUE,  FALSE,  FALSE,  TRUE},
     { 0,        FALSE,  FALSE,   TRUE,  TRUE},
@@ -587,50 +583,50 @@ static struct {
 
 /* test_ok_wndproc can be used as hook procedure or a subclass
  * window proc for the file dialog */
-static LONG_PTR WINAPI test_ok_wndproc(HWND dlg, UINT msg, WPARAM wParam, LPARAM lParam)
+static UINT_PTR WINAPI test_ok_wndproc(HWND dlg, UINT msg, WPARAM wParam, LPARAM lParam)
 {
     HWND parent = GetParent( dlg);
-    static int index;
+    static ok_wndproc_testcase *testcase = NULL;
     static UINT msgFILEOKSTRING;
     if (msg == WM_INITDIALOG)
     {
-        index = ((OPENFILENAME*)lParam)->lCustData;
-        ok_testcases[index].actclose = TRUE;
-        msgFILEOKSTRING = RegisterWindowMessageA( FILEOKSTRING);
+        testcase = (ok_wndproc_testcase*)((OPENFILENAMEA*)lParam)->lCustData;
+        testcase->actclose = TRUE;
+        msgFILEOKSTRING = RegisterWindowMessageA( FILEOKSTRINGA);
     }
     if( msg == WM_NOTIFY) {
         if(((LPNMHDR)lParam)->code == CDN_FOLDERCHANGE) {
             SetTimer( dlg, 0, 100, 0);
-            PostMessage( parent, WM_COMMAND, IDOK, 0);
+            PostMessageA( parent, WM_COMMAND, IDOK, 0);
             return FALSE;
         } else if(((LPNMHDR)lParam)->code == CDN_FILEOK) {
-            if( ok_testcases[index].usemsgokstr)
+            if( testcase->usemsgokstr)
                 return FALSE;
-            if( ok_testcases[index].setmsgresult)
-                SetWindowLongPtrA( dlg, DWLP_MSGRESULT, ok_testcases[index].retval);
-            return ok_testcases[index].retval;
+            if( testcase->setmsgresult)
+                SetWindowLongPtrA( dlg, DWLP_MSGRESULT, testcase->retval);
+            return testcase->retval;
         }
     }
     if( msg == msgFILEOKSTRING) {
-        if( !ok_testcases[index].usemsgokstr)
+        if( !testcase->usemsgokstr)
             return FALSE;
-        if( ok_testcases[index].setmsgresult)
-            SetWindowLongPtrA( dlg, DWLP_MSGRESULT, ok_testcases[index].retval);
-        return ok_testcases[index].retval;
+        if( testcase->setmsgresult)
+            SetWindowLongPtrA( dlg, DWLP_MSGRESULT, testcase->retval);
+        return testcase->retval;
     }
     if( msg == WM_TIMER) {
         /* the dialog did not close automatically */
-        ok_testcases[index].actclose = FALSE;
+        testcase->actclose = FALSE;
         KillTimer( dlg, 0);
-        PostMessage( parent, WM_COMMAND, IDCANCEL, 0);
+        PostMessageA( parent, WM_COMMAND, IDCANCEL, 0);
         return FALSE;
     }
-    if( ok_testcases[index].do_subclass)
-        return DefWindowProc( dlg, msg, wParam, lParam);
+    if( testcase && testcase->do_subclass)
+        return DefWindowProcA( dlg, msg, wParam, lParam);
     return FALSE;
 }
 
-static LONG_PTR WINAPI ok_template_hook(HWND dlg, UINT msg, WPARAM wParam, LPARAM lParam)
+static UINT_PTR WINAPI ok_template_hook(HWND dlg, UINT msg, WPARAM wParam, LPARAM lParam)
 {
     if (msg == WM_SETFONT)
         SetWindowLongPtrA( dlg, GWLP_WNDPROC, (LONG_PTR) test_ok_wndproc);
@@ -639,29 +635,29 @@ static LONG_PTR WINAPI ok_template_hook(HWND dlg, UINT msg, WPARAM wParam, LPARA
 
 static void test_ok(void)
 {
-    OPENFILENAME ofn = { sizeof(OPENFILENAME)};
+    OPENFILENAMEA ofn = { OPENFILENAME_SIZE_VERSION_400A };
     char filename[1024] = {0};
     char tmpfilename[ MAX_PATH];
     char curdir[MAX_PATH];
     int i;
     DWORD ret;
+    BOOL cdret;
 
-    ok(GetCurrentDirectoryA(sizeof(curdir), curdir) != 0, "Failed to get current dir err %d\n", GetLastError());
+    cdret = GetCurrentDirectoryA(sizeof(curdir), curdir);
+    ok(cdret, "Failed to get current dir err %d\n", GetLastError());
     if (!GetTempFileNameA(".", "txt", 0, tmpfilename)) {
         skip("Failed to create a temporary file name\n");
         return;
     }
     ofn.lpstrFile = filename;
     ofn.nMaxFile = 1024;
-    ofn.hInstance = GetModuleHandle(NULL);
+    ofn.hInstance = GetModuleHandleA(NULL);
     ofn.lpTemplateName = "template1";
     ofn.Flags =  OFN_ENABLEHOOK | OFN_EXPLORER| OFN_ENABLETEMPLATE ;
     for( i = 0; ok_testcases[i].retval != -1; i++) {
         strcpy( filename, tmpfilename);
-        ofn.lCustData = i;
-        ofn.lpfnHook = ok_testcases[i].do_subclass
-            ? (LPOFNHOOKPROC) ok_template_hook
-            : (LPOFNHOOKPROC) test_ok_wndproc;
+        ofn.lCustData = (LPARAM)(ok_testcases + i);
+        ofn.lpfnHook = ok_testcases[i].do_subclass ? ok_template_hook : test_ok_wndproc;
         ret = GetOpenFileNameA(&ofn);
         ok( ok_testcases[i].expclose == ok_testcases[i].actclose,
                 "testid %d: Open File dialog should %shave closed.\n", i,
@@ -669,7 +665,8 @@ static void test_ok(void)
         ok(ret == ok_testcases[i].expclose, "testid %d: GetOpenFileName returned %#x\n", i, ret);
         ret = CommDlgExtendedError();
         ok(!ret, "CommDlgExtendedError returned %#x\n", ret);
-        ok(SetCurrentDirectoryA(curdir), "Failed to restore current dir err %d\n", GetLastError());
+        cdret = SetCurrentDirectoryA(curdir);
+        ok(cdret, "Failed to restore current dir err %d\n", GetLastError());
     }
     ret =  DeleteFileA( tmpfilename);
     ok( ret, "Failed to delete temporary file %s err %d\n", tmpfilename, GetLastError());
@@ -709,7 +706,7 @@ static struct {
     { -1 }
 };
 
-static LONG_PTR WINAPI template_hook_arrange(HWND dlgChild, UINT msg, WPARAM wParam, LPARAM lParam)
+static UINT_PTR WINAPI template_hook_arrange(HWND dlgChild, UINT msg, WPARAM wParam, LPARAM lParam)
 {
     static int index, fixhelp;
     static posz posz0[2];
@@ -719,7 +716,7 @@ static LONG_PTR WINAPI template_hook_arrange(HWND dlgChild, UINT msg, WPARAM wPa
 
     dlgParent = GetParent( dlgChild);
     if (msg == WM_INITDIALOG) {
-        index = ((OPENFILENAME*)lParam)->lCustData;
+        index = ((OPENFILENAMEA*)lParam)->lCustData;
         /* get the positions before rearrangement */
         GetClientRect( dlgParent, &clrcParent);
         GetClientRect( dlgChild, &clrcChild);
@@ -760,7 +757,7 @@ static LONG_PTR WINAPI template_hook_arrange(HWND dlgChild, UINT msg, WPARAM wPa
                 /* special case: there is a control with id stc32 */
                 /* expected height */
                 expecty = posz0[withhelp].cy;
-                if( rcStc32.bottom - rcStc32.top > clrcParent.bottom) {
+                if( rcStc32.bottom - rcStc32.top + (withhelp ? 0 : fixhelp) > clrcParent.bottom) {
                     expecty +=  clrcChild.bottom -  clrcParent.bottom;
                     if( !withhelp) expecty += fixhelp;
                 }
@@ -774,7 +771,7 @@ static LONG_PTR WINAPI template_hook_arrange(HWND dlgChild, UINT msg, WPARAM wPa
                 else
                     expectx +=  clrcChild.right - ( rcStc32.right - rcStc32.left) ;
             }
-            style = GetWindowLong( dlgParent, GWL_STYLE);
+            style = GetWindowLongA( dlgParent, GWL_STYLE);
             if( !(style & WS_SIZEBOX)) {
                 /* without the OFN_ENABLESIZING flag */
                 ok( wrcParent.bottom - wrcParent.top == expecty,
@@ -783,7 +780,7 @@ static LONG_PTR WINAPI template_hook_arrange(HWND dlgChild, UINT msg, WPARAM wPa
                 ok( wrcParent.right - wrcParent.left == expectx,
                         "Wrong width of dialog %d, expected %d\n",
                         wrcParent.right - wrcParent.left, expectx);
-            } else todo_wine {
+            } else {
                 /* with the OFN_ENABLESIZING flag */
                 ok( wrcParent.bottom - wrcParent.top > expecty,
                         "Wrong height of dialog %d, expected more than %d\n",
@@ -794,7 +791,7 @@ static LONG_PTR WINAPI template_hook_arrange(HWND dlgChild, UINT msg, WPARAM wPa
             }
 
         }
-        PostMessage( dlgParent, WM_COMMAND, IDCANCEL, 0);
+        PostMessageA( dlgParent, WM_COMMAND, IDCANCEL, 0);
     }
     return 0;
 }
@@ -812,8 +809,8 @@ static void test_arrange(void)
     int i;
 
     /* load subdialog template into memory */
-    hRes = FindResource( GetModuleHandle(NULL), "template_stc32", (LPSTR)RT_DIALOG);
-    hDlgTmpl = LoadResource( GetModuleHandle(NULL), hRes );
+    hRes = FindResourceA( GetModuleHandleA(NULL), "template_stc32", (LPSTR)RT_DIALOG);
+    hDlgTmpl = LoadResource( GetModuleHandleA(NULL), hRes );
     /* get pointers to the structures for the dialog and the controls */
     pv = LockResource( hDlgTmpl );
     template = (DLGTEMPLATE*)pv;
@@ -846,10 +843,10 @@ static void test_arrange(void)
         return;
     }
 
-    ofn.lStructSize = sizeof(ofn);
+    ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400A;
     ofn.lpstrFile = filename;
     ofn.nMaxFile = 1024;
-    ofn.lpfnHook = (LPOFNHOOKPROC)template_hook_arrange;
+    ofn.lpfnHook = template_hook_arrange;
     ofn.hInstance = hDlgTmpl;
     ofn.lpstrFilter="text\0*.txt\0All\0*\0\0";
     for( i = 0; arrange_tests[i].nrcontrols != -1; i++) {
@@ -887,7 +884,7 @@ static UINT_PTR CALLBACK path_hook_proc( HWND hDlg, UINT msg, WPARAM wParam, LPA
         nmh = (LPNMHDR) lParam;
         if( nmh->code == CDN_INITDONE)
         {
-            PostMessage( GetParent(hDlg), WM_COMMAND, IDCANCEL, FALSE);
+            PostMessageA( GetParent(hDlg), WM_COMMAND, IDCANCEL, FALSE);
         }
         else if ( nmh->code == CDN_FOLDERCHANGE)
         {
@@ -914,12 +911,12 @@ static void test_getfolderpath(void)
     /* We need to pick a different directory as the other tests because of new
      * Windows 7 behavior.
      */
-    GetSystemDirectory(szInitialDir, MAX_PATH);
+    GetSystemDirectoryA(szInitialDir, MAX_PATH);
     lstrcpyA(SYSDIR, szInitialDir);
 
     ZeroMemory(&ofn, sizeof(ofn));
 
-    ofn.lStructSize = sizeof(ofn);
+    ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400A;
     ofn.hwndOwner = NULL;
     ofn.lpstrFilter = "Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0";
     ofn.lpstrFile = szFileName;
@@ -930,12 +927,12 @@ static void test_getfolderpath(void)
     ofn.lpstrInitialDir = szInitialDir;
 
     result = GetOpenFileNameA(&ofn);
-    ok(0 == result, "expected 0, got %d\n", result);
+    ok(FALSE == result, "expected FALSE, got %d\n", result);
     ok(0 == CommDlgExtendedError(), "expected 0, got %d\n",
        CommDlgExtendedError());
 
     result = GetSaveFileNameA(&ofn);
-    ok(0 == result, "expected 0, got %d\n", result);
+    ok(FALSE == result, "expected FALSE, got %d\n", result);
     ok(0 == CommDlgExtendedError(), "expected 0, got %d\n",
        CommDlgExtendedError());
 }
@@ -951,14 +948,14 @@ static void test_resizable2(void)
         skip( "some interactive resizable dialog tests (set WINETEST_INTERACTIVE=1)\n");
         return;
     }
-    ofn.lStructSize = sizeof(ofn);
+    ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400A;
     ofn.lpstrFile = filename;
     ofn.nMaxFile = 1024;
     ofn.lpfnHook = NULL;
     ofn.hInstance = GetModuleHandleA(NULL);
     ofn.lpTemplateName = "template1";
     ofn.Flags = OFN_EXPLORER;
-#define ISSIZABLE 1
+#define ISSIZABLE TRUE
     ret = GetOpenFileNameA(&ofn);
     ok( ret == ISSIZABLE, "File Dialog should have been sizable\n");
     ret = CommDlgExtendedError();
@@ -969,7 +966,7 @@ static void test_resizable2(void)
     ret = CommDlgExtendedError();
     ok(!ret, "CommDlgExtendedError returned %#x\n", ret);
     ofn.Flags = OFN_EXPLORER | OFN_ENABLETEMPLATEHANDLE;
-    ofn.hInstance = LoadResource( GetModuleHandle(NULL), FindResource( GetModuleHandle(NULL), "template1", (LPSTR)RT_DIALOG));
+    ofn.hInstance = LoadResource( GetModuleHandleA(NULL), FindResourceA( GetModuleHandleA(NULL), "template1", (LPSTR)RT_DIALOG));
     ofn.lpTemplateName = NULL;
     ret = GetOpenFileNameA(&ofn);
     ok( ret != ISSIZABLE, "File Dialog should NOT have been sizable\n");
@@ -983,6 +980,268 @@ static void test_resizable2(void)
 #undef ISSIZABLE
 }
 
+static void test_mru(void)
+{
+    ok_wndproc_testcase testcase = {0};
+    OPENFILENAMEA ofn = { OPENFILENAME_SIZE_VERSION_400A };
+    const char *test_dir_name = "C:\\mru_test";
+    const char *test_file_name = "test.txt";
+    const char *test_full_path = "C:\\mru_test\\test.txt";
+    char filename_buf[MAX_PATH];
+    DWORD ret;
+
+    ofn.lpstrFile = filename_buf;
+    ofn.nMaxFile = sizeof(filename_buf);
+    ofn.lpTemplateName = "template1";
+    ofn.hInstance = GetModuleHandleA(NULL);
+    ofn.Flags =  OFN_ENABLEHOOK | OFN_EXPLORER | OFN_ENABLETEMPLATE | OFN_NOCHANGEDIR;
+    ofn.lCustData = (LPARAM)&testcase;
+    ofn.lpfnHook = test_ok_wndproc;
+
+    SetLastError(0xdeadbeef);
+    ret = CreateDirectoryA(test_dir_name, NULL);
+    ok(ret == TRUE, "CreateDirectoryA should have succeeded: %d\n", GetLastError());
+
+    /* "teach" comdlg32 about this directory */
+    strcpy(filename_buf, test_full_path);
+    SetLastError(0xdeadbeef);
+    ret = GetOpenFileNameA(&ofn);
+    ok(ret, "GetOpenFileNameA should have succeeded: %d\n", GetLastError());
+    ret = CommDlgExtendedError();
+    ok(!ret, "CommDlgExtendedError returned %x\n", ret);
+    ok(testcase.actclose, "Open File dialog should have closed.\n");
+    ok(!strcmp(ofn.lpstrFile, test_full_path), "Expected to get %s, got %s\n", test_full_path, ofn.lpstrFile);
+
+    /* get a filename without a full path. it should return the file in
+     * test_dir_name, not in the CWD */
+    strcpy(filename_buf, test_file_name);
+    SetLastError(0xdeadbeef);
+    ret = GetOpenFileNameA(&ofn);
+    ok(ret, "GetOpenFileNameA should have succeeded: %d\n", GetLastError());
+    ret = CommDlgExtendedError();
+    ok(!ret, "CommDlgExtendedError returned %x\n", ret);
+    ok(testcase.actclose, "Open File dialog should have closed.\n");
+    if(strcmp(ofn.lpstrFile, test_full_path) != 0)
+        win_skip("Platform doesn't save MRU data\n");
+
+    SetLastError(0xdeadbeef);
+    ret = RemoveDirectoryA(test_dir_name);
+    ok(ret == TRUE, "RemoveDirectoryA should have succeeded: %d\n", GetLastError());
+}
+
+static UINT_PTR WINAPI test_extension_wndproc(HWND dlg, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+    HWND parent = GetParent( dlg);
+    if( msg == WM_NOTIFY) {
+        SetTimer( dlg, 0, 1000, 0);
+        PostMessageA( parent, WM_COMMAND, IDOK, 0);
+    }
+    if( msg == WM_TIMER) {
+        /* the dialog did not close automatically */
+        KillTimer( dlg, 0);
+        PostMessageA( parent, WM_COMMAND, IDCANCEL, 0);
+    }
+    return FALSE;
+}
+
+#define ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0]))
+
+static void test_extension_helper(OPENFILENAMEA* ofn, const char *filter,
+                                  const char *expected_filename)
+{
+    char *filename_ptr;
+    DWORD ret;
+    BOOL boolret;
+
+    strcpy(ofn->lpstrFile, "deadbeef");
+    ofn->lpstrFilter = filter;
+
+    boolret = GetSaveFileNameA(ofn);
+    ok(boolret, "%s: expected TRUE\n", filter);
+
+    ret = CommDlgExtendedError();
+    ok(!ret, "%s: CommDlgExtendedError returned %#x\n", filter, ret);
+
+    filename_ptr = ofn->lpstrFile + ofn->nFileOffset;
+    ok(strcmp(filename_ptr, expected_filename) == 0,
+        "%s: Filename is %s, expected %s\n", filter, filename_ptr, expected_filename);
+}
+
+static void test_extension(void)
+{
+    OPENFILENAMEA ofn = { OPENFILENAME_SIZE_VERSION_400A };
+    char filename[1024] = {0};
+    char curdir[MAX_PATH];
+    unsigned int i;
+    BOOL boolret;
+
+    const char *defext_concrete_filters[] = {
+        "TestFilter (*.abc)\0*.abc\0",
+        "TestFilter (*.abc;)\0*.abc;\0",
+        "TestFilter (*.abc;*.def)\0*.abc;*.def\0",
+    };
+
+    const char *defext_wildcard_filters[] = {
+        "TestFilter (*.pt*)\0*.pt*\0",
+        "TestFilter (*.pt*;*.abc)\0*.pt*;*.abc\0",
+        "TestFilter (*.ab?)\0*.ab?\0",
+        "TestFilter (*.*)\0*.*\0",
+        "TestFilter (*sav)\0*sav\0",
+        NULL    /* is a test, not an endmark! */
+    };
+
+    boolret = GetCurrentDirectoryA(sizeof(curdir), curdir);
+    ok(boolret, "Failed to get current dir err %d\n", GetLastError());
+
+    ofn.hwndOwner = NULL;
+    ofn.lpstrFile = filename;
+    ofn.nMaxFile = MAX_PATH;
+    ofn.Flags = OFN_EXPLORER | OFN_ENABLEHOOK;
+    ofn.lpstrInitialDir = curdir;
+    ofn.lpfnHook = test_extension_wndproc;
+    ofn.nFileExtension = 0;
+
+    ofn.lpstrDefExt = NULL;
+
+    /* Without lpstrDefExt, append no extension */
+    test_extension_helper(&ofn, "TestFilter (*.abc) lpstrDefExt=NULL\0*.abc\0", "deadbeef");
+    test_extension_helper(&ofn, "TestFilter (*.ab?) lpstrDefExt=NULL\0*.ab?\0", "deadbeef");
+
+    ofn.lpstrDefExt = "";
+
+    /* If lpstrDefExt="" and the filter has a concrete extension, append it */
+    test_extension_helper(&ofn, "TestFilter (*.abc) lpstrDefExt=\"\"\0*.abc\0", "deadbeef.abc");
+
+    /* If lpstrDefExt="" and the filter has a wildcard extension, do nothing */
+    test_extension_helper(&ofn, "TestFilter (*.ab?) lpstrDefExt=\"\"\0*.ab?\0", "deadbeef");
+
+    ofn.lpstrDefExt = "xyz";
+
+    /* Append concrete extensions from filters */
+    for (i = 0; i < ARRAY_SIZE(defext_concrete_filters); i++) {
+        test_extension_helper(&ofn, defext_concrete_filters[i], "deadbeef.abc");
+    }
+
+    /* Append nothing from this filter */
+    test_extension_helper(&ofn, "TestFilter (*.)\0*.\0", "deadbeef");
+
+    /* Ignore wildcard extensions in filters */
+    for (i = 0; i < ARRAY_SIZE(defext_wildcard_filters); i++) {
+        test_extension_helper(&ofn, defext_wildcard_filters[i], "deadbeef.xyz");
+    }
+
+    /* Append valid extensions consisting of multiple parts */
+    test_extension_helper(&ofn, "TestFilter (*.abc.def)\0*.abc.def\0", "deadbeef.abc.def");
+    test_extension_helper(&ofn, "TestFilter (.abc.def)\0.abc.def\0", "deadbeef.abc.def");
+    test_extension_helper(&ofn, "TestFilter (*.*.def)\0*.*.def\0", "deadbeef.xyz");
+}
+
+#undef ARRAY_SIZE
+
+
+static BOOL WINAPI test_null_enum(HWND hwnd, LPARAM lParam)
+{
+    /* Find the textbox and send a filename so IDOK will work.
+       If the file textbox is empty IDOK will be ignored */
+    CHAR className[20];
+    if(GetClassNameA(hwnd, className, sizeof(className)) > 0 && !strcmp("Edit",className))
+    {
+        SetWindowTextA(hwnd, "testfile");
+        return FALSE; /* break window enumeration */
+    }
+    return TRUE;
+}
+
+static UINT_PTR WINAPI test_null_wndproc(HWND dlg, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+    HWND parent = GetParent( dlg);
+    if( msg == WM_NOTIFY) {
+        SetTimer( dlg, 0, 100, 0);
+        SetTimer( dlg, 1, 1000, 0);
+        EnumChildWindows( parent, test_null_enum, 0);
+    }
+    if( msg == WM_TIMER) {
+        if(!wParam)
+            PostMessageA( parent, WM_COMMAND, IDOK, 0);
+        else {
+            /* the dialog did not close automatically */
+            KillTimer( dlg, 0);
+            PostMessageA( parent, WM_COMMAND, IDCANCEL, 0);
+        }
+    }
+    return FALSE;
+}
+
+static void test_null_filename(void)
+{
+    OPENFILENAMEA ofnA = {0};
+    OPENFILENAMEW ofnW = {0};
+    WCHAR filterW[] = {'t','e','x','t','\0','*','.','t','x','t','\0',
+                       'A','l','l','\0','*','\0','\0'};
+    DWORD ret;
+
+    ofnA.lStructSize = OPENFILENAME_SIZE_VERSION_400A;
+    ofnA.lpstrFile = NULL;
+    ofnA.nMaxFile = 0;
+    ofnA.nFileOffset = 0xdead;
+    ofnA.nFileExtension = 0xbeef;
+    ofnA.lpfnHook = test_null_wndproc;
+    ofnA.Flags = OFN_ENABLEHOOK | OFN_EXPLORER;
+    ofnA.hInstance = GetModuleHandleA(NULL);
+    ofnA.lpstrFilter = "text\0*.txt\0All\0*\0\0";
+    ofnA.lpstrDefExt = NULL;
+    ret = GetOpenFileNameA(&ofnA);
+    todo_wine ok(ret, "GetOpenFileNameA returned %#x\n", ret);
+    ret = CommDlgExtendedError();
+    todo_wine ok(!ret, "CommDlgExtendedError returned %#x, should be 0\n", ret);
+
+    todo_wine ok(ofnA.nFileOffset != 0xdead, "ofnA.nFileOffset is 0xdead\n");
+    todo_wine ok(ofnA.nFileExtension != 0xbeef, "ofnA.nFileExtension is 0xbeef\n");
+
+    ofnA.lpstrFile = NULL;
+    ofnA.nMaxFile = 1024; /* bogus input - lpstrFile = NULL but fake 1024 bytes available */
+    ofnA.nFileOffset = 0xdead;
+    ofnA.nFileExtension = 0xbeef;
+    ret = GetOpenFileNameA(&ofnA);
+    ok(ret, "GetOpenFileNameA returned %#x\n", ret);
+    ret = CommDlgExtendedError();
+    ok(!ret, "CommDlgExtendedError returned %#x\n", ret);
+
+    ok(ofnA.nFileOffset != 0xdead, "ofnA.nFileOffset is 0xdead\n");
+    ok(ofnA.nFileExtension == 0, "ofnA.nFileExtension is 0x%x, should be 0\n", ofnA.nFileExtension);
+
+    /* unicode tests */
+    ofnW.lStructSize = OPENFILENAME_SIZE_VERSION_400W;
+    ofnW.lpstrFile = NULL;
+    ofnW.nMaxFile = 0;
+    ofnW.nFileOffset = 0xdead;
+    ofnW.nFileExtension = 0xbeef;
+    ofnW.lpfnHook = test_null_wndproc;
+    ofnW.Flags = OFN_ENABLEHOOK | OFN_EXPLORER;
+    ofnW.hInstance = GetModuleHandleW(NULL);
+    ofnW.lpstrFilter = filterW;
+    ofnW.lpstrDefExt = NULL;
+    ret = GetOpenFileNameW(&ofnW);
+    todo_wine ok(ret, "GetOpenFileNameW returned %#x\n", ret);
+    ret = CommDlgExtendedError();
+    todo_wine ok(!ret, "CommDlgExtendedError returned %#x\n", ret);
+
+    todo_wine ok(ofnW.nFileOffset != 0xdead, "ofnW.nFileOffset is 0xdead\n");
+    todo_wine ok(ofnW.nFileExtension != 0xbeef, "ofnW.nFileExtension is 0xbeef\n");
+
+    ofnW.lpstrFile = NULL;
+    ofnW.nMaxFile = 1024; /* bogus input - lpstrFile = NULL but fake 1024 bytes available */
+    ofnW.nFileOffset = 0xdead;
+    ofnW.nFileExtension = 0xbeef;
+    ret = GetOpenFileNameW(&ofnW);
+    ok(ret, "GetOpenFileNameA returned %#x\n", ret);
+    ret = CommDlgExtendedError();
+    ok(!ret, "CommDlgExtendedError returned %#x\n", ret);
+
+    ok(ofnW.nFileOffset != 0xdead, "ofnW.nFileOffset is 0xdead\n");
+    ok(ofnW.nFileExtension == 0, "ofnW.nFileExtension is 0x%x, should be 0\n", ofnW.nFileExtension);
+}
+
 START_TEST(filedlg)
 {
     test_DialogCancel();
@@ -992,5 +1251,8 @@ START_TEST(filedlg)
     test_resize();
     test_ok();
     test_getfolderpath();
+    test_mru();
     if( resizesupported) test_resizable2();
+    test_extension();
+    test_null_filename();
 }