d3dcompiler: Add argument check in D3DReflect().
[wine] / dlls / user32 / tests / class.c
1 /* Unit test suite for window classes.
2  *
3  * Copyright 2002 Mike McCormack
4  * Copyright 2003 Alexandre Julliard
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 /* To get CS_DROPSHADOW with the MSVC headers */
22 #define _WIN32_WINNT 0x0501
23
24 #include <assert.h>
25 #include <stdlib.h>
26 #include <stdarg.h>
27 #include <stdio.h>
28
29 #include "wine/test.h"
30 #include "windef.h"
31 #include "winbase.h"
32 #include "winreg.h"
33 #include "wingdi.h"
34 #include "winuser.h"
35
36 /* we don't want to include commctrl.h: */
37 static const CHAR WC_EDITA[] = "Edit";
38 static const WCHAR WC_EDITW[] = {'E','d','i','t',0};
39
40 #define NUMCLASSWORDS 4
41
42 #define IS_WNDPROC_HANDLE(x) (((ULONG_PTR)(x) >> 16) == (~0u >> 16))
43
44 static LRESULT WINAPI ClassTest_WndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
45 {
46     if (msg == WM_NCCREATE) return 1;
47     return DefWindowProcW (hWnd, msg, wParam, lParam);
48 }
49
50 static LRESULT WINAPI ClassTest_WndProc2 (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
51 {
52     if (msg == WM_NCCREATE) return 1;
53     return DefWindowProcA (hWnd, msg, wParam, lParam);
54 }
55
56 /***********************************************************************
57  */
58 static void ClassTest(HINSTANCE hInstance, BOOL global)
59 {
60     WNDCLASSW cls, wc;
61     static const WCHAR className[] = {'T','e','s','t','C','l','a','s','s',0};
62     static const WCHAR winName[]   = {'W','i','n','C','l','a','s','s','T','e','s','t',0};
63     ATOM test_atom;
64     HWND hTestWnd;
65     LONG i;
66     WCHAR str[20];
67     ATOM classatom;
68
69     cls.style         = CS_HREDRAW | CS_VREDRAW | (global?CS_GLOBALCLASS:0);
70     cls.lpfnWndProc   = ClassTest_WndProc;
71     cls.cbClsExtra    = NUMCLASSWORDS*sizeof(DWORD);
72     cls.cbWndExtra    = 12;
73     cls.hInstance     = hInstance;
74     cls.hIcon         = LoadIconW (0, (LPWSTR)IDI_APPLICATION);
75     cls.hCursor       = LoadCursorW (0, (LPWSTR)IDC_ARROW);
76     cls.hbrBackground = GetStockObject (WHITE_BRUSH);
77     cls.lpszMenuName  = 0;
78     cls.lpszClassName = className;
79
80     classatom=RegisterClassW(&cls);
81     if (!classatom && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
82         return;
83     ok(classatom, "failed to register class\n");
84
85     ok(!RegisterClassW (&cls),
86         "RegisterClass of the same class should fail for the second time\n");
87
88     /* Setup windows */
89     hTestWnd = CreateWindowW (className, winName,
90        WS_OVERLAPPEDWINDOW + WS_HSCROLL + WS_VSCROLL,
91        CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, 0,
92        0, hInstance, 0);
93
94     ok(hTestWnd!=0, "Failed to create window\n");
95
96     /* test initial values of valid classwords */
97     for(i=0; i<NUMCLASSWORDS; i++)
98     {
99         SetLastError(0);
100         ok(!GetClassLongW(hTestWnd,i*sizeof (DWORD)),
101             "GetClassLongW initial value nonzero!\n");
102         ok(!GetLastError(),
103             "GetClassLongW failed!\n");
104     }
105
106     if (0)
107     {
108     /*
109      *  GetClassLongW(hTestWnd, NUMCLASSWORDS*sizeof(DWORD))
110      *  does not fail on Win 98, though MSDN says it should
111      */
112     SetLastError(0);
113     GetClassLongW(hTestWnd, NUMCLASSWORDS*sizeof(DWORD));
114     ok(GetLastError(),
115         "GetClassLongW() with invalid offset did not fail\n");
116     }
117
118     /* set values of valid class words */
119     for(i=0; i<NUMCLASSWORDS; i++)
120     {
121         SetLastError(0);
122         ok(!SetClassLongW(hTestWnd,i*sizeof(DWORD),i+1),
123             "GetClassLongW(%d) initial value nonzero!\n",i);
124         ok(!GetLastError(),
125             "SetClassLongW(%d) failed!\n",i);
126     }
127
128     /* test values of valid classwords that we set */
129     for(i=0; i<NUMCLASSWORDS; i++)
130     {
131         SetLastError(0);
132         ok( (i+1) == GetClassLongW(hTestWnd,i*sizeof (DWORD)),
133             "GetClassLongW value doesn't match what was set!\n");
134         ok(!GetLastError(),
135             "GetClassLongW failed!\n");
136     }
137
138     /* check GetClassName */
139     i = GetClassNameW(hTestWnd, str, sizeof(str)/sizeof(str[0]));
140     ok(i == lstrlenW(className),
141         "GetClassName returned incorrect length\n");
142     ok(!lstrcmpW(className,str),
143         "GetClassName returned incorrect name for this window's class\n");
144
145     /* check GetClassInfo with our hInstance */
146     if((test_atom = GetClassInfoW(hInstance, str, &wc)))
147     {
148         ok(test_atom == classatom,
149             "class atom did not match\n");
150         ok(wc.cbClsExtra == cls.cbClsExtra,
151             "cbClsExtra did not match\n");
152         ok(wc.cbWndExtra == cls.cbWndExtra,
153             "cbWndExtra did not match\n");
154         ok(wc.hbrBackground == cls.hbrBackground,
155             "hbrBackground did not match\n");
156         ok(wc.hCursor== cls.hCursor,
157             "hCursor did not match\n");
158         ok(wc.hInstance== cls.hInstance,
159             "hInstance did not match\n");
160     }
161     else
162         ok(FALSE,"GetClassInfo (hinstance) failed!\n");
163
164     /* check GetClassInfo with zero hInstance */
165     if(global)
166     {
167         if((test_atom = GetClassInfoW(0, str, &wc)))
168         {
169             ok(test_atom == classatom,
170                 "class atom did not match %x != %x\n", test_atom, classatom);
171             ok(wc.cbClsExtra == cls.cbClsExtra,
172                 "cbClsExtra did not match %x!=%x\n",wc.cbClsExtra,cls.cbClsExtra);
173             ok(wc.cbWndExtra == cls.cbWndExtra,
174                 "cbWndExtra did not match %x!=%x\n",wc.cbWndExtra,cls.cbWndExtra);
175             ok(wc.hbrBackground == cls.hbrBackground,
176                 "hbrBackground did not match %p!=%p\n",wc.hbrBackground,cls.hbrBackground);
177             ok(wc.hCursor== cls.hCursor,
178                 "hCursor did not match %p!=%p\n",wc.hCursor,cls.hCursor);
179             ok(!wc.hInstance,
180                 "hInstance not zero for global class %p\n",wc.hInstance);
181         }
182         else
183             ok(FALSE,"GetClassInfo (0) failed for global class!\n");
184     }
185     else
186     {
187         ok(!GetClassInfoW(0, str, &wc),
188             "GetClassInfo (0) succeeded for local class!\n");
189     }
190
191     ok(!UnregisterClassW(className, hInstance),
192         "Unregister class succeeded with window existing\n");
193
194     ok(DestroyWindow(hTestWnd),
195         "DestroyWindow() failed!\n");
196
197     ok(UnregisterClassW(className, hInstance),
198         "UnregisterClass() failed\n");
199
200     return;
201 }
202
203 static void check_style( const char *name, int must_exist, UINT style, UINT ignore )
204 {
205     WNDCLASS wc;
206
207     if (GetClassInfo( 0, name, &wc ))
208     {
209         ok( !(~wc.style & style & ~ignore), "System class %s is missing bits %x (%08x/%08x)\n",
210             name, ~wc.style & style, wc.style, style );
211         ok( !(wc.style & ~style), "System class %s has extra bits %x (%08x/%08x)\n",
212             name, wc.style & ~style, wc.style, style );
213     }
214     else
215         ok( !must_exist, "System class %s does not exist\n", name );
216 }
217
218 /* test styles of system classes */
219 static void test_styles(void)
220 {
221     /* check style bits */
222     check_style( "Button",     1, CS_PARENTDC | CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW, 0 );
223     check_style( "ComboBox",   1, CS_PARENTDC | CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW, 0 );
224     check_style( "Edit",       1, CS_PARENTDC | CS_DBLCLKS, 0 );
225     check_style( "ListBox",    1, CS_PARENTDC | CS_DBLCLKS, CS_PARENTDC /*FIXME*/ );
226     check_style( "MDIClient",  1, 0, 0 );
227     check_style( "ScrollBar",  1, CS_PARENTDC | CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW, 0 );
228     check_style( "Static",     1, CS_PARENTDC | CS_DBLCLKS, 0 );
229     check_style( "ComboLBox",  1, CS_SAVEBITS | CS_DBLCLKS, 0 );
230     check_style( "DDEMLEvent", 0, 0, 0 );
231     check_style( "Message",    0, 0, 0 );
232     check_style( "#32768",     1, CS_DROPSHADOW | CS_SAVEBITS | CS_DBLCLKS, CS_DROPSHADOW );  /* menu */
233     check_style( "#32769",     1, CS_DBLCLKS, 0 );  /* desktop */
234     check_style( "#32770",     1, CS_SAVEBITS | CS_DBLCLKS, 0 );  /* dialog */
235     todo_wine { check_style( "#32771",     1, CS_SAVEBITS | CS_HREDRAW | CS_VREDRAW, 0 ); } /* task switch */
236     check_style( "#32772",     1, 0, 0 );  /* icon title */
237 }
238
239 static void check_class_(int line, HINSTANCE inst, const char *name, const char *menu_name)
240 {
241     WNDCLASS wc;
242     UINT atom = GetClassInfo(inst,name,&wc);
243     ok_(__FILE__,line)( atom, "Class %s %p not found\n", name, inst );
244     if (atom)
245     {
246         if (wc.lpszMenuName && menu_name)
247             ok_(__FILE__,line)( !strcmp( menu_name, wc.lpszMenuName ),
248                                 "Wrong name %s/%s for class %s %p\n",
249                                 wc.lpszMenuName, menu_name, name, inst );
250         else
251             ok_(__FILE__,line)( !menu_name == !wc.lpszMenuName, "Wrong name %p/%p for class %s %p\n",
252                                 wc.lpszMenuName, menu_name, name, inst );
253     }
254 }
255 #define check_class(inst,name,menu) check_class_(__LINE__,inst,name,menu)
256
257 static void check_instance_( int line, const char *name, HINSTANCE inst,
258                              HINSTANCE info_inst, HINSTANCE gcl_inst )
259 {
260     WNDCLASSA wc;
261     HWND hwnd;
262
263     ok_(__FILE__,line)( GetClassInfo( inst, name, &wc ), "Couldn't find class %s inst %p\n", name, inst );
264     ok_(__FILE__,line)( wc.hInstance == info_inst, "Wrong info instance %p/%p for class %s\n",
265                         wc.hInstance, info_inst, name );
266     hwnd = CreateWindowExA( 0, name, "test_window", 0, 0, 0, 0, 0, 0, 0, inst, 0 );
267     ok_(__FILE__,line)( hwnd != NULL, "Couldn't create window for class %s inst %p\n", name, inst );
268     ok_(__FILE__,line)( (HINSTANCE)GetClassLongPtrA( hwnd, GCLP_HMODULE ) == gcl_inst,
269                         "Wrong GCL instance %p/%p for class %s\n",
270         (HINSTANCE)GetClassLongPtrA( hwnd, GCLP_HMODULE ), gcl_inst, name );
271     ok_(__FILE__,line)( (HINSTANCE)GetWindowLongPtrA( hwnd, GWLP_HINSTANCE ) == inst,
272                         "Wrong GWL instance %p/%p for window %s\n",
273         (HINSTANCE)GetWindowLongPtrA( hwnd, GWLP_HINSTANCE ), inst, name );
274     ok_(__FILE__,line)(!UnregisterClassA(name, inst),
275                        "UnregisterClassA should fail while exists a class window\n");
276     ok_(__FILE__,line)(GetLastError() == ERROR_CLASS_HAS_WINDOWS,
277                        "GetLastError() should be set to ERROR_CLASS_HAS_WINDOWS not %d\n", GetLastError());
278     DestroyWindow(hwnd);
279 }
280 #define check_instance(name,inst,info_inst,gcl_inst) check_instance_(__LINE__,name,inst,info_inst,gcl_inst)
281
282 struct class_info
283 {
284     const char *name;
285     HINSTANCE inst, info_inst, gcl_inst;
286 };
287
288 static DWORD WINAPI thread_proc(void *param)
289 {
290     struct class_info *class_info = param;
291
292     check_instance(class_info->name, class_info->inst, class_info->info_inst, class_info->gcl_inst);
293
294     return 0;
295 }
296
297 static void check_thread_instance( const char *name, HINSTANCE inst, HINSTANCE info_inst, HINSTANCE gcl_inst )
298 {
299     HANDLE hThread;
300     DWORD tid;
301     struct class_info class_info;
302
303     class_info.name = name;
304     class_info.inst = inst;
305     class_info.info_inst = info_inst;
306     class_info.gcl_inst = gcl_inst;
307
308     hThread = CreateThread(NULL, 0, thread_proc, &class_info, 0, &tid);
309     ok(hThread != NULL, "CreateThread failed, error %d\n", GetLastError());
310     ok(WaitForSingleObject(hThread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
311     CloseHandle(hThread);
312 }
313
314 /* test various instance parameters */
315 static void test_instances(void)
316 {
317     WNDCLASSA cls, wc;
318     WNDCLASSEXA wcexA;
319     HWND hwnd, hwnd2;
320     const char *name = "__test__";
321     HINSTANCE kernel32 = GetModuleHandleA("kernel32");
322     HINSTANCE user32 = GetModuleHandleA("user32");
323     HINSTANCE main_module = GetModuleHandleA(NULL);
324     HINSTANCE zero_instance = 0;
325     DWORD r;
326     char buffer[0x10];
327
328     memset( &cls, 0, sizeof(cls) );
329     cls.style         = CS_HREDRAW | CS_VREDRAW;
330     cls.lpfnWndProc   = ClassTest_WndProc;
331     cls.cbClsExtra    = 0;
332     cls.cbWndExtra    = 0;
333     cls.lpszClassName = name;
334
335     cls.lpszMenuName  = "main_module";
336     cls.hInstance = main_module;
337
338     ok( RegisterClassA( &cls ), "Failed to register local class for main module\n" );
339     check_class( main_module, name, "main_module" );
340     check_instance( name, main_module, main_module, main_module );
341     check_thread_instance( name, main_module, main_module, main_module );
342
343     cls.lpszMenuName  = "kernel32";
344     cls.hInstance = kernel32;
345     ok( RegisterClassA( &cls ), "Failed to register local class for kernel32\n" );
346     check_class( kernel32, name, "kernel32" );
347     check_class( main_module, name, "main_module" );
348     check_instance( name, kernel32, kernel32, kernel32 );
349     check_thread_instance( name, kernel32, kernel32, kernel32 );
350     ok( UnregisterClassA( name, kernel32 ), "Unregister failed for kernel32\n" );
351
352     ZeroMemory(&wcexA, sizeof(wcexA));
353     wcexA.lpfnWndProc = DefWindowProcA;
354     wcexA.lpszClassName = "__classex_test__";
355     SetLastError(0xdeadbeef);
356     wcexA.cbSize = sizeof(wcexA) - 1;
357     ok( ((RegisterClassExA( &wcexA ) == 0) && (GetLastError() == ERROR_INVALID_PARAMETER)),
358           "Succeeded with invalid number of cbSize bytes\n");
359     SetLastError(0xdeadbeef);
360     wcexA.cbSize = sizeof(wcexA) + 1;
361     ok( ((RegisterClassExA( &wcexA ) == 0) && (GetLastError() == ERROR_INVALID_PARAMETER)),
362           "Succeeded with invalid number of cbSize bytes\n");
363     SetLastError(0xdeadbeef);
364     wcexA.cbSize = sizeof(wcexA);
365     ok( RegisterClassExA( &wcexA ), "Failed with valid number of cbSize bytes\n");
366     wcexA.cbSize = 0xdeadbeef;
367     ok( GetClassInfoEx(main_module, wcexA.lpszClassName, &wcexA), "GetClassInfoEx failed\n");
368     ok( wcexA.cbSize == 0xdeadbeef, "GetClassInfoEx returned wrong cbSize value %d\n", wcexA.cbSize);
369     UnregisterClassA(wcexA.lpszClassName, main_module);
370
371     /* Bug 2631 - Supplying an invalid number of bytes fails */
372     cls.cbClsExtra    = 0;
373     cls.cbWndExtra    = -1;
374     SetLastError(0xdeadbeef);
375     ok( ((RegisterClassA( &cls ) == 0) && (GetLastError() == ERROR_INVALID_PARAMETER)),
376           "Failed with invalid number of WndExtra bytes\n");
377
378     cls.cbClsExtra    = -1;
379     cls.cbWndExtra    = 0;
380     SetLastError(0xdeadbeef);
381     ok( ((RegisterClassA( &cls ) == 0) && (GetLastError() == ERROR_INVALID_PARAMETER)),
382           "Failed with invalid number of ClsExtra bytes\n");
383
384     cls.cbClsExtra    = -1;
385     cls.cbWndExtra    = -1;
386     SetLastError(0xdeadbeef);
387     ok( ((RegisterClassA( &cls ) == 0) && (GetLastError() == ERROR_INVALID_PARAMETER)),
388           "Failed with invalid number of ClsExtra and cbWndExtra bytes\n");
389
390     cls.cbClsExtra    = 0;
391     cls.cbWndExtra    = 0;
392     SetLastError(0xdeadbeef);
393
394     /* setting global flag doesn't change status of class */
395     hwnd = CreateWindowExA( 0, name, "test", 0, 0, 0, 0, 0, 0, 0, main_module, 0 );
396     ok( hwnd != 0, "CreateWindow failed error %u\n", GetLastError());
397     SetClassLongA( hwnd, GCL_STYLE, CS_GLOBALCLASS );
398     cls.lpszMenuName  = "kernel32";
399     cls.hInstance = kernel32;
400     ok( RegisterClassA( &cls ), "Failed to register local class for kernel32\n" );
401     check_class( kernel32, name, "kernel32" );
402     check_class( main_module, name, "main_module" );
403     check_instance( name, kernel32, kernel32, kernel32 );
404     check_instance( name, main_module, main_module, main_module );
405     check_thread_instance( name, kernel32, kernel32, kernel32 );
406     check_thread_instance( name, main_module, main_module, main_module );
407     ok( UnregisterClassA( name, kernel32 ), "Unregister failed for kernel32\n" );
408
409     /* changing the instance doesn't make it global */
410     SetClassLongPtrA( hwnd, GCLP_HMODULE, 0 );
411     ok( RegisterClassA( &cls ), "Failed to register local class for kernel32\n" );
412     check_class( kernel32, name, "kernel32" );
413     check_instance( name, kernel32, kernel32, kernel32 );
414     check_thread_instance( name, kernel32, kernel32, kernel32 );
415     ok( !GetClassInfo( 0, name, &wc ), "Class found with null instance\n" );
416     ok( UnregisterClassA( name, kernel32 ), "Unregister failed for kernel32\n" );
417
418     /* GetClassInfo with instance 0 finds user32 instance */
419     SetClassLongPtrA( hwnd, GCLP_HMODULE, (LONG_PTR)user32 );
420     ok( RegisterClassA( &cls ), "Failed to register local class for kernel32\n" );
421     if (!GetClassInfo( 0, name, &wc )) zero_instance = user32; /* instance 0 not supported on wow64 */
422     else
423     {
424         check_instance( name, 0, 0, kernel32 );
425         check_thread_instance( name, 0, 0, kernel32 );
426     }
427     check_class( kernel32, name, "kernel32" );
428     check_class( user32, name, "main_module" );
429     check_class( zero_instance, name, "main_module" );
430     check_instance( name, kernel32, kernel32, kernel32 );
431     check_instance( name, user32, zero_instance, user32 );
432     check_thread_instance( name, kernel32, kernel32, kernel32 );
433     check_thread_instance( name, user32, zero_instance, user32 );
434     ok( UnregisterClassA( name, kernel32 ), "Unregister failed for kernel32\n" );
435
436     SetClassLongPtrA( hwnd, GCLP_HMODULE, 0x12345678 );
437     ok( RegisterClassA( &cls ), "Failed to register local class for kernel32\n" );
438     check_class( kernel32, name, "kernel32" );
439     check_class( (HINSTANCE)0x12345678, name, "main_module" );
440     check_instance( name, kernel32, kernel32, kernel32 );
441     check_instance( name, (HINSTANCE)0x12345678, (HINSTANCE)0x12345678, (HINSTANCE)0x12345678 );
442     check_thread_instance( name, kernel32, kernel32, kernel32 );
443     check_thread_instance( name, (HINSTANCE)0x12345678, (HINSTANCE)0x12345678, (HINSTANCE)0x12345678 );
444     ok( !GetClassInfo( 0, name, &wc ), "Class found with null instance\n" );
445
446     /* creating a window with instance 0 uses the first class found */
447     cls.hInstance = (HINSTANCE)0xdeadbeef;
448     cls.lpszMenuName = "deadbeef";
449     cls.style = 3;
450     ok( RegisterClassA( &cls ), "Failed to register local class for deadbeef\n" );
451     hwnd2 = CreateWindowExA( 0, name, "test_window", 0, 0, 0, 0, 0, 0, 0, NULL, 0 );
452     ok( GetClassLongPtrA( hwnd2, GCLP_HMODULE ) == 0xdeadbeef,
453         "Didn't get deadbeef class for null instance\n" );
454     DestroyWindow( hwnd2 );
455     ok( UnregisterClassA( name, (HINSTANCE)0xdeadbeef ), "Unregister failed for deadbeef\n" );
456
457     hwnd2 = CreateWindowExA( 0, name, "test_window", 0, 0, 0, 0, 0, 0, 0, NULL, 0 );
458     ok( (HINSTANCE)GetClassLongPtrA( hwnd2, GCLP_HMODULE ) == kernel32,
459         "Didn't get kernel32 class for null instance\n" );
460     DestroyWindow( hwnd2 );
461
462     r = GetClassName( hwnd, buffer, 4 );
463     ok( r == 3, "expected 3, got %d\n", r );
464     ok( !strcmp( buffer, "__t"), "name wrong: %s\n", buffer );
465
466     ok( UnregisterClassA( name, kernel32 ), "Unregister failed for kernel32\n" );
467
468     hwnd2 = CreateWindowExA( 0, name, "test_window", 0, 0, 0, 0, 0, 0, 0, NULL, 0 );
469     ok( GetClassLongPtrA( hwnd2, GCLP_HMODULE ) == 0x12345678,
470         "Didn't get 12345678 class for null instance\n" );
471     DestroyWindow( hwnd2 );
472
473     SetClassLongPtrA( hwnd, GCLP_HMODULE, (LONG_PTR)main_module );
474     DestroyWindow( hwnd );
475
476     /* null handle means the same thing as main module */
477     cls.lpszMenuName  = "null";
478     cls.hInstance = 0;
479     ok( !RegisterClassA( &cls ), "Succeeded registering local class for null instance\n" );
480     ok( GetLastError() == ERROR_CLASS_ALREADY_EXISTS, "Wrong error code %d\n", GetLastError() );
481     ok( UnregisterClassA( name, main_module ), "Unregister failed for main module\n" );
482
483     ok( RegisterClassA( &cls ), "Failed to register local class for null instance\n" );
484     /* must be found with main module handle */
485     check_class( main_module, name, "null" );
486     check_instance( name, main_module, main_module, main_module );
487     check_thread_instance( name, main_module, main_module, main_module );
488     ok( !GetClassInfo( 0, name, &wc ), "Class found with null instance\n" );
489     ok( GetLastError() == ERROR_CLASS_DOES_NOT_EXIST, "Wrong error code %d\n", GetLastError() );
490     ok( UnregisterClassA( name, 0 ), "Unregister failed for null instance\n" );
491
492     /* registering for user32 always fails */
493     cls.lpszMenuName = "user32";
494     cls.hInstance = user32;
495     ok( !RegisterClassA( &cls ), "Succeeded registering local class for user32\n" );
496     ok( GetLastError() == ERROR_INVALID_PARAMETER, "Wrong error code %d\n", GetLastError() );
497     cls.style |= CS_GLOBALCLASS;
498     ok( !RegisterClassA( &cls ), "Succeeded registering global class for user32\n" );
499     ok( GetLastError() == ERROR_INVALID_PARAMETER, "Wrong error code %d\n", GetLastError() );
500
501     /* unregister is OK though */
502     cls.hInstance = main_module;
503     ok( RegisterClassA( &cls ), "Failed to register global class for main module\n" );
504     ok( UnregisterClassA( name, user32 ), "Unregister failed for user32\n" );
505
506     /* instance doesn't matter for global class */
507     cls.style |= CS_GLOBALCLASS;
508     cls.lpszMenuName  = "main_module";
509     cls.hInstance = main_module;
510     ok( RegisterClassA( &cls ), "Failed to register global class for main module\n" );
511     cls.lpszMenuName  = "kernel32";
512     cls.hInstance = kernel32;
513     ok( !RegisterClassA( &cls ), "Succeeded registering local class for kernel32\n" );
514     ok( GetLastError() == ERROR_CLASS_ALREADY_EXISTS, "Wrong error code %d\n", GetLastError() );
515     /* even if global flag is cleared */
516     hwnd = CreateWindowExA( 0, name, "test", 0, 0, 0, 0, 0, 0, 0, main_module, 0 );
517     SetClassLongA( hwnd, GCL_STYLE, 0 );
518     ok( !RegisterClassA( &cls ), "Succeeded registering local class for kernel32\n" );
519     ok( GetLastError() == ERROR_CLASS_ALREADY_EXISTS, "Wrong error code %d\n", GetLastError() );
520
521     check_class( main_module, name, "main_module" );
522     check_class( kernel32, name, "main_module" );
523     check_class( 0, name, "main_module" );
524     check_class( (HINSTANCE)0x12345678, name, "main_module" );
525     check_instance( name, main_module, main_module, main_module );
526     check_instance( name, (HINSTANCE)0xdeadbeef, (HINSTANCE)0xdeadbeef, main_module );
527     check_thread_instance( name, main_module, main_module, main_module );
528     check_thread_instance( name, (HINSTANCE)0xdeadbeef, (HINSTANCE)0xdeadbeef, main_module );
529
530     /* changing the instance for global class doesn't make much difference */
531     SetClassLongPtrA( hwnd, GCLP_HMODULE, 0xdeadbeef );
532     check_instance( name, main_module, main_module, (HINSTANCE)0xdeadbeef );
533     check_instance( name, (HINSTANCE)0xdeadbeef, (HINSTANCE)0xdeadbeef, (HINSTANCE)0xdeadbeef );
534     check_thread_instance( name, main_module, main_module, (HINSTANCE)0xdeadbeef );
535     check_thread_instance( name, (HINSTANCE)0xdeadbeef, (HINSTANCE)0xdeadbeef, (HINSTANCE)0xdeadbeef );
536
537     DestroyWindow( hwnd );
538     ok( UnregisterClassA( name, (HINSTANCE)0x87654321 ), "Unregister failed for main module global\n" );
539     ok( !UnregisterClassA( name, (HINSTANCE)0x87654321 ), "Unregister succeeded the second time\n" );
540     ok( GetLastError() == ERROR_CLASS_DOES_NOT_EXIST, "Wrong error code %d\n", GetLastError() );
541
542     cls.hInstance = (HINSTANCE)0x12345678;
543     ok( RegisterClassA( &cls ), "Failed to register global class for dummy instance\n" );
544     check_instance( name, main_module, main_module, (HINSTANCE)0x12345678 );
545     check_instance( name, (HINSTANCE)0xdeadbeef, (HINSTANCE)0xdeadbeef, (HINSTANCE)0x12345678 );
546     check_thread_instance( name, main_module, main_module, (HINSTANCE)0x12345678 );
547     check_thread_instance( name, (HINSTANCE)0xdeadbeef, (HINSTANCE)0xdeadbeef, (HINSTANCE)0x12345678 );
548     ok( UnregisterClassA( name, (HINSTANCE)0x87654321 ), "Unregister failed for main module global\n" );
549
550     /* check system classes */
551
552     /* we cannot register a global class with the name of a system class */
553     cls.style |= CS_GLOBALCLASS;
554     cls.lpszMenuName  = "button_main_module";
555     cls.lpszClassName = "BUTTON";
556     cls.hInstance = main_module;
557     ok( !RegisterClassA( &cls ), "Succeeded registering global button class for main module\n" );
558     ok( GetLastError() == ERROR_CLASS_ALREADY_EXISTS, "Wrong error code %d\n", GetLastError() );
559     cls.hInstance = kernel32;
560     ok( !RegisterClassA( &cls ), "Succeeded registering global button class for kernel32\n" );
561     ok( GetLastError() == ERROR_CLASS_ALREADY_EXISTS, "Wrong error code %d\n", GetLastError() );
562
563     /* local class is OK however */
564     cls.style &= ~CS_GLOBALCLASS;
565     cls.lpszMenuName  = "button_main_module";
566     cls.hInstance = main_module;
567     ok( RegisterClassA( &cls ), "Failed to register local button class for main module\n" );
568     check_class( main_module, "BUTTON", "button_main_module" );
569     cls.lpszMenuName  = "button_kernel32";
570     cls.hInstance = kernel32;
571     ok( RegisterClassA( &cls ), "Failed to register local button class for kernel32\n" );
572     check_class( kernel32, "BUTTON", "button_kernel32" );
573     check_class( main_module, "BUTTON", "button_main_module" );
574     ok( UnregisterClassA( "BUTTON", kernel32 ), "Unregister failed for kernel32 button\n" );
575     ok( UnregisterClassA( "BUTTON", main_module ), "Unregister failed for main module button\n" );
576     /* GetClassInfo sets instance to passed value for global classes */
577     check_instance( "BUTTON", 0, 0, user32 );
578     check_instance( "BUTTON", (HINSTANCE)0xdeadbeef, (HINSTANCE)0xdeadbeef, user32 );
579     check_instance( "BUTTON", user32, zero_instance, user32 );
580     check_thread_instance( "BUTTON", 0, 0, user32 );
581     check_thread_instance( "BUTTON", (HINSTANCE)0xdeadbeef, (HINSTANCE)0xdeadbeef, user32 );
582     check_thread_instance( "BUTTON", user32, zero_instance, user32 );
583
584     /* we can unregister system classes */
585     ok( GetClassInfo( 0, "BUTTON", &wc ), "Button class not found with null instance\n" );
586     ok( GetClassInfo( kernel32, "BUTTON", &wc ), "Button class not found with kernel32\n" );
587     ok( UnregisterClass( "BUTTON", (HINSTANCE)0x12345678 ), "Failed to unregister button\n" );
588     ok( !UnregisterClass( "BUTTON", (HINSTANCE)0x87654321 ), "Unregistered button a second time\n" );
589     ok( GetLastError() == ERROR_CLASS_DOES_NOT_EXIST, "Wrong error code %d\n", GetLastError() );
590     ok( !GetClassInfo( 0, "BUTTON", &wc ), "Button still exists\n" );
591     /* last error not set reliably */
592
593     /* we can change the instance of a system class */
594     check_instance( "EDIT", (HINSTANCE)0xdeadbeef, (HINSTANCE)0xdeadbeef, user32 );
595     check_thread_instance( "EDIT", (HINSTANCE)0xdeadbeef, (HINSTANCE)0xdeadbeef, user32 );
596     hwnd = CreateWindowExA( 0, "EDIT", "test", 0, 0, 0, 0, 0, 0, 0, main_module, 0 );
597     SetClassLongPtrA( hwnd, GCLP_HMODULE, 0xdeadbeef );
598     check_instance( "EDIT", (HINSTANCE)0x12345678, (HINSTANCE)0x12345678, (HINSTANCE)0xdeadbeef );
599     check_thread_instance( "EDIT", (HINSTANCE)0x12345678, (HINSTANCE)0x12345678, (HINSTANCE)0xdeadbeef );
600     DestroyWindow(hwnd);
601 }
602
603 static void test_builtinproc(void)
604 {
605     /* Edit behaves differently */
606     static const CHAR NORMAL_CLASSES[][10] = {
607         "Button",
608         "Static",
609         "ComboBox",
610         "ComboLBox",
611         "ListBox",
612         "ScrollBar",
613         "#32770",  /* dialog */
614     };
615     static const int NUM_NORMAL_CLASSES = (sizeof(NORMAL_CLASSES)/sizeof(NORMAL_CLASSES[0]));
616     static const char classA[] = "deftest";
617     static const WCHAR classW[] = {'d','e','f','t','e','s','t',0};
618     WCHAR unistring[] = {0x142, 0x40e, 0x3b4, 0};  /* a string that would be destroyed by a W->A->W conversion */
619     WNDPROC pDefWindowProcA, pDefWindowProcW;
620     WNDPROC pNtdllDefWindowProcA, pNtdllDefWindowProcW;
621     WNDPROC oldproc;
622     WNDCLASSEXA cls;  /* the memory layout of WNDCLASSEXA and WNDCLASSEXW is the same */
623     WCHAR buf[128];
624     ATOM atom;
625     HWND hwnd;
626     int i;
627
628     pDefWindowProcA = (void *)GetProcAddress(GetModuleHandle("user32.dll"), "DefWindowProcA");
629     pDefWindowProcW = (void *)GetProcAddress(GetModuleHandle("user32.dll"), "DefWindowProcW");
630     pNtdllDefWindowProcA = (void *)GetProcAddress(GetModuleHandle("ntdll.dll"), "NtdllDefWindowProc_A");
631     pNtdllDefWindowProcW = (void *)GetProcAddress(GetModuleHandle("ntdll.dll"), "NtdllDefWindowProc_W");
632
633     /* On Vista+, the user32.dll export DefWindowProcA/W is forwarded to  */
634     /* ntdll.NtdllDefWindowProc_A/W. However, the wndproc returned by     */
635     /* GetClassLong/GetWindowLong points to an unexported user32 function */
636     if (pDefWindowProcA == pNtdllDefWindowProcA &&
637         pDefWindowProcW == pNtdllDefWindowProcW)
638         skip("user32.DefWindowProcX forwarded to ntdll.NtdllDefWindowProc_X\n");
639     else
640     {
641         for (i = 0; i < 4; i++)
642         {
643             ZeroMemory(&cls, sizeof(cls));
644             cls.cbSize = sizeof(cls);
645             cls.hInstance = GetModuleHandle(NULL);
646             cls.hbrBackground = GetStockObject (WHITE_BRUSH);
647             if (i & 1)
648                 cls.lpfnWndProc = pDefWindowProcA;
649             else
650                 cls.lpfnWndProc = pDefWindowProcW;
651
652             if (i & 2)
653             {
654                 cls.lpszClassName = classA;
655                 atom = RegisterClassExA(&cls);
656             }
657             else
658             {
659                 cls.lpszClassName = (LPCSTR)classW;
660                 atom = RegisterClassExW((WNDCLASSEXW *)&cls);
661             }
662             ok(atom != 0, "Couldn't register class, i=%d, %d\n", i, GetLastError());
663
664             hwnd = CreateWindowA(classA, NULL, 0, 0, 0, 100, 100, NULL, NULL, GetModuleHandle(NULL), NULL);
665             ok(hwnd != NULL, "Couldn't create window i=%d\n", i);
666
667             ok(GetWindowLongPtrA(hwnd, GWLP_WNDPROC) == (LONG_PTR)pDefWindowProcA, "Wrong ANSI wndproc: %p vs %p\n",
668                 (void *)GetWindowLongPtrA(hwnd, GWLP_WNDPROC), pDefWindowProcA);
669             ok(GetClassLongPtrA(hwnd, GCLP_WNDPROC) == (ULONG_PTR)pDefWindowProcA, "Wrong ANSI wndproc: %p vs %p\n",
670                 (void *)GetClassLongPtrA(hwnd, GCLP_WNDPROC), pDefWindowProcA);
671
672             ok(GetWindowLongPtrW(hwnd, GWLP_WNDPROC) == (LONG_PTR)pDefWindowProcW, "Wrong Unicode wndproc: %p vs %p\n",
673                 (void *)GetWindowLongPtrW(hwnd, GWLP_WNDPROC), pDefWindowProcW);
674             ok(GetClassLongPtrW(hwnd, GCLP_WNDPROC) == (ULONG_PTR)pDefWindowProcW, "Wrong Unicode wndproc: %p vs %p\n",
675                 (void *)GetClassLongPtrW(hwnd, GCLP_WNDPROC), pDefWindowProcW);
676
677             DestroyWindow(hwnd);
678             UnregisterClass((LPSTR)(DWORD_PTR)atom, GetModuleHandle(NULL));
679         }
680     }
681
682     /* built-in winproc - window A/W type automatically detected */
683     ZeroMemory(&cls, sizeof(cls));
684     cls.cbSize = sizeof(cls);
685     cls.hInstance = GetModuleHandle(NULL);
686     cls.hbrBackground = GetStockObject (WHITE_BRUSH);
687     cls.lpszClassName = classA;
688     cls.lpfnWndProc = pDefWindowProcW;
689     atom = RegisterClassExA(&cls);
690
691     hwnd = CreateWindowExW(0, classW, NULL, WS_OVERLAPPEDWINDOW,
692         CW_USEDEFAULT, CW_USEDEFAULT, 680, 260, NULL, NULL, GetModuleHandleA(NULL), 0);
693     ok(IsWindowUnicode(hwnd), "Windows should be Unicode\n");
694     SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (LONG_PTR)pDefWindowProcA);
695     ok(IsWindowUnicode(hwnd), "Windows should have remained Unicode\n");
696     if (GetWindowLongPtrW(hwnd, GWLP_WNDPROC) == (LONG_PTR)pDefWindowProcA)
697     {
698         /* DefWindowProc isn't magic on wow64 */
699         ok(IS_WNDPROC_HANDLE(GetWindowLongPtrA(hwnd, GWLP_WNDPROC)), "Ansi winproc is not a handle\n");
700     }
701     else
702     {
703         ok(GetWindowLongPtrW(hwnd, GWLP_WNDPROC) == (LONG_PTR)pDefWindowProcW, "Invalid Unicode winproc\n");
704         ok(GetWindowLongPtrA(hwnd, GWLP_WNDPROC) == (LONG_PTR)pDefWindowProcA, "Invalid Ansi winproc\n");
705     }
706     SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (LONG_PTR)ClassTest_WndProc);
707     ok(IsWindowUnicode(hwnd) == FALSE, "SetWindowLongPtrA should have switched window to ANSI\n");
708
709     DestroyWindow(hwnd);
710     UnregisterClass((LPSTR)(DWORD_PTR)atom, GetModuleHandle(NULL));
711
712     /* custom winproc - the same function can be used as both A and W*/
713     ZeroMemory(&cls, sizeof(cls));
714     cls.cbSize = sizeof(cls);
715     cls.hInstance = GetModuleHandle(NULL);
716     cls.hbrBackground = GetStockObject (WHITE_BRUSH);
717     cls.lpszClassName = classA;
718     cls.lpfnWndProc = ClassTest_WndProc2;
719     atom = RegisterClassExA(&cls);
720
721     hwnd = CreateWindowExW(0, classW, NULL, WS_OVERLAPPEDWINDOW,
722         CW_USEDEFAULT, CW_USEDEFAULT, 680, 260, NULL, NULL, GetModuleHandleA(NULL), 0);
723     ok(IsWindowUnicode(hwnd) == FALSE, "Window should be ANSI\n");
724     SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (LONG_PTR)ClassTest_WndProc);
725     ok(IsWindowUnicode(hwnd), "SetWindowLongPtrW should have changed window to Unicode\n");
726     SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (LONG_PTR)ClassTest_WndProc);
727     ok(IsWindowUnicode(hwnd) == FALSE, "SetWindowLongPtrA should have changed window to ANSI\n");
728
729     DestroyWindow(hwnd);
730     UnregisterClass((LPSTR)(DWORD_PTR)atom, GetModuleHandle(NULL));
731
732     /* For most of the builtin controls both GetWindowLongPtrA and W returns a pointer that is executed directly
733      * by CallWindowProcA/W */
734     for (i = 0; i < NUM_NORMAL_CLASSES; i++)
735     {
736         WNDPROC procA, procW;
737         hwnd = CreateWindowExA(0, NORMAL_CLASSES[i], classA, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 680, 260,
738             NULL, NULL, NULL, 0);
739         ok(hwnd != NULL, "Couldn't create window of class %s\n", NORMAL_CLASSES[i]);
740         SetWindowText(hwnd, classA);  /* ComboBox needs this */
741         procA = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_WNDPROC);
742         procW = (WNDPROC)GetWindowLongPtrW(hwnd, GWLP_WNDPROC);
743         ok(!IS_WNDPROC_HANDLE(procA), "procA should not be a handle for %s (%p)\n", NORMAL_CLASSES[i], procA);
744         ok(!IS_WNDPROC_HANDLE(procW), "procW should not be a handle for %s (%p)\n", NORMAL_CLASSES[i], procW);
745         CallWindowProcA(procA, hwnd, WM_GETTEXT, 120, (LPARAM)buf);
746         ok(memcmp(buf, classA, sizeof(classA)) == 0, "WM_GETTEXT A/A invalid return for class %s\n", NORMAL_CLASSES[i]);
747         CallWindowProcA(procW, hwnd, WM_GETTEXT, 120, (LPARAM)buf);
748         ok(memcmp(buf, classW, sizeof(classW)) == 0, "WM_GETTEXT A/W invalid return for class %s\n", NORMAL_CLASSES[i]);
749         CallWindowProcW(procA, hwnd, WM_GETTEXT, 120, (LPARAM)buf);
750         ok(memcmp(buf, classA, sizeof(classA)) == 0, "WM_GETTEXT W/A invalid return for class %s\n", NORMAL_CLASSES[i]);
751         CallWindowProcW(procW, hwnd, WM_GETTEXT, 120, (LPARAM)buf);
752         ok(memcmp(buf, classW, sizeof(classW)) == 0, "WM_GETTEXT W/W invalid return for class %s\n", NORMAL_CLASSES[i]);
753
754         oldproc = (WNDPROC)SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (LONG_PTR)ClassTest_WndProc);
755         ok(IS_WNDPROC_HANDLE(oldproc) == FALSE, "Class %s shouldn't return a handle\n", NORMAL_CLASSES[i]);
756         SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (LONG_PTR)oldproc);
757         DestroyWindow(hwnd);
758     }
759
760     /* Edit controls are special - they return a wndproc handle when GetWindowLongPtr is called with a different A/W.
761      * On the other hand there is no W->A->W conversion so this control is treated specially. */
762     hwnd = CreateWindowW(WC_EDITW, unistring, WS_OVERLAPPEDWINDOW,
763       CW_USEDEFAULT, CW_USEDEFAULT, 680, 260, NULL, NULL, NULL, 0);
764     /* GetClassLongPtr returns that both the Unicode and ANSI wndproc */
765     ok(IS_WNDPROC_HANDLE(GetClassLongPtrA(hwnd, GCLP_WNDPROC)) == FALSE, "Edit control class should have a Unicode wndproc\n");
766     ok(IS_WNDPROC_HANDLE(GetClassLongPtrW(hwnd, GCLP_WNDPROC)) == FALSE, "Edit control class should have a ANSI wndproc\n");
767     /* But GetWindowLongPtr returns only a handle for the ANSI one */
768     ok(IS_WNDPROC_HANDLE(GetWindowLongPtrA(hwnd, GWLP_WNDPROC)), "Edit control should return a wndproc handle\n");
769     ok(!IS_WNDPROC_HANDLE(GetWindowLongPtrW(hwnd, GWLP_WNDPROC)), "Edit control shouldn't return a W wndproc handle\n");
770     CallWindowProcW((WNDPROC)GetWindowLongPtrW(hwnd, GWLP_WNDPROC), hwnd, WM_GETTEXT, 120, (LPARAM)buf);
771     ok(memcmp(buf, unistring, sizeof(unistring)) == 0, "WM_GETTEXT invalid return\n");
772     CallWindowProcA((WNDPROC)GetWindowLongPtrW(hwnd, GWLP_WNDPROC), hwnd, WM_GETTEXT, 120, (LPARAM)buf);
773     ok(memcmp(buf, unistring, sizeof(unistring)) == 0, "WM_GETTEXT invalid return\n");
774     CallWindowProcW((WNDPROC)GetWindowLongPtrA(hwnd, GWLP_WNDPROC), hwnd, WM_GETTEXT, 120, (LPARAM)buf);
775     ok(memcmp(buf, unistring, sizeof(unistring)) == 0, "WM_GETTEXT invalid return\n");
776
777     SetWindowTextW(hwnd, classW);
778     CallWindowProcA((WNDPROC)GetWindowLongPtrA(hwnd, GWLP_WNDPROC), hwnd, WM_GETTEXT, 120, (LPARAM)buf);
779     ok(memcmp(buf, classA, sizeof(classA)) == 0, "WM_GETTEXT invalid return\n");
780
781     oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (LONG_PTR)ClassTest_WndProc2);
782     /* SetWindowLongPtr returns a wndproc handle - like GetWindowLongPtr */
783     ok(IS_WNDPROC_HANDLE(oldproc), "Edit control should return a wndproc handle\n");
784     ok(IsWindowUnicode(hwnd) == FALSE, "SetWindowLongPtrA should have changed window to ANSI\n");
785     SetWindowTextA(hwnd, classA);  /* Windows resets the title to WideStringToMultiByte(unistring) */
786     memset(buf, 0, sizeof(buf));
787     CallWindowProcA((WNDPROC)GetWindowLongPtrA(hwnd, GWLP_WNDPROC), hwnd, WM_GETTEXT, 120, (LPARAM)buf);
788     ok(memcmp(buf, classA, sizeof(classA)) == 0, "WM_GETTEXT invalid return\n");
789     CallWindowProcA((WNDPROC)GetWindowLongPtrW(hwnd, GWLP_WNDPROC), hwnd, WM_GETTEXT, 120, (LPARAM)buf);
790     ok(memcmp(buf, classA, sizeof(classA)) == 0, "WM_GETTEXT invalid return\n");
791     CallWindowProcW((WNDPROC)GetWindowLongPtrA(hwnd, GWLP_WNDPROC), hwnd, WM_GETTEXT, 120, (LPARAM)buf);
792     ok(memcmp(buf, classA, sizeof(classA)) == 0, "WM_GETTEXT invalid return\n");
793
794     CallWindowProcW((WNDPROC)GetWindowLongPtrW(hwnd, GWLP_WNDPROC), hwnd, WM_GETTEXT, 120, (LPARAM)buf);
795     ok(memcmp(buf, classW, sizeof(classW)) == 0, "WM_GETTEXT invalid return\n");
796
797     SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (LONG_PTR)oldproc);
798
799     DestroyWindow(hwnd);
800
801     hwnd = CreateWindowA(WC_EDITA, classA, WS_OVERLAPPEDWINDOW,
802       CW_USEDEFAULT, CW_USEDEFAULT, 680, 260, NULL, NULL, NULL, 0);
803
804     /* GetClassLongPtr returns that both the Unicode and ANSI wndproc */
805     ok(!IS_WNDPROC_HANDLE(GetClassLongPtrA(hwnd, GCLP_WNDPROC)), "Edit control class should have a Unicode wndproc\n");
806     ok(!IS_WNDPROC_HANDLE(GetClassLongPtrW(hwnd, GCLP_WNDPROC)), "Edit control class should have a ANSI wndproc\n");
807     /* But GetWindowLongPtr returns only a handle for the Unicode one */
808     ok(!IS_WNDPROC_HANDLE(GetWindowLongPtrA(hwnd, GWLP_WNDPROC)), "Edit control shouldn't return an A wndproc handle\n");
809     ok(IS_WNDPROC_HANDLE(GetWindowLongPtrW(hwnd, GWLP_WNDPROC)), "Edit control should return a wndproc handle\n");
810     CallWindowProcA((WNDPROC)GetWindowLongPtrA(hwnd, GWLP_WNDPROC), hwnd, WM_GETTEXT, 120, (LPARAM)buf);
811     ok(memcmp(buf, classA, sizeof(classA)) == 0, "WM_GETTEXT invalid return\n");
812     CallWindowProcA((WNDPROC)GetWindowLongPtrW(hwnd, GWLP_WNDPROC), hwnd, WM_GETTEXT, 120, (LPARAM)buf);
813     ok(memcmp(buf, classA, sizeof(classA)) == 0, "WM_GETTEXT invalid return\n");
814     CallWindowProcW((WNDPROC)GetWindowLongPtrA(hwnd, GWLP_WNDPROC), hwnd, WM_GETTEXT, 120, (LPARAM)buf);
815     ok(memcmp(buf, classA, sizeof(classA)) == 0, "WM_GETTEXT invalid return\n");
816
817     CallWindowProcW((WNDPROC)GetWindowLongPtrW(hwnd, GWLP_WNDPROC), hwnd, WM_GETTEXT, 120, (LPARAM)buf);
818     ok(memcmp(buf, classW, sizeof(classW)) == 0, "WM_GETTEXT invalid return\n");
819
820     oldproc = (WNDPROC)SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (LONG_PTR)ClassTest_WndProc);
821     SetWindowTextW(hwnd, unistring);
822     CallWindowProcW((WNDPROC)GetWindowLongPtrW(hwnd, GWLP_WNDPROC), hwnd, WM_GETTEXT, 120, (LPARAM)buf);
823     ok(memcmp(buf, unistring, sizeof(unistring)) == 0, "WM_GETTEXT invalid return\n");
824     CallWindowProcA((WNDPROC)GetWindowLongPtrW(hwnd, GWLP_WNDPROC), hwnd, WM_GETTEXT, 120, (LPARAM)buf);
825     ok(memcmp(buf, unistring, sizeof(unistring)) == 0, "WM_GETTEXT invalid return\n");
826     CallWindowProcW((WNDPROC)GetWindowLongPtrA(hwnd, GWLP_WNDPROC), hwnd, WM_GETTEXT, 120, (LPARAM)buf);
827     ok(memcmp(buf, unistring, sizeof(unistring)) == 0, "WM_GETTEXT invalid return\n");
828
829     SetWindowTextW(hwnd, classW);
830     CallWindowProcA((WNDPROC)GetWindowLongPtrA(hwnd, GWLP_WNDPROC), hwnd, WM_GETTEXT, 120, (LPARAM)buf);
831     ok(memcmp(buf, classA, sizeof(classA)) == 0, "WM_GETTEXT invalid return\n");
832
833     SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (LONG_PTR)oldproc);
834
835     DestroyWindow(hwnd);
836 }
837
838
839 static LRESULT WINAPI TestDlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
840 {
841     return DefWindowProc(hWnd, uMsg, wParam, lParam);
842 }
843
844 static BOOL RegisterTestDialog(HINSTANCE hInstance)
845 {
846     WNDCLASSEX wcx;
847     ATOM atom = 0;
848
849     ZeroMemory(&wcx, sizeof(WNDCLASSEX));
850     wcx.cbSize = sizeof(wcx);
851     wcx.lpfnWndProc = TestDlgProc;
852     wcx.cbClsExtra = 0;
853     wcx.cbWndExtra = DLGWINDOWEXTRA;
854     wcx.hInstance = hInstance;
855     wcx.hIcon = LoadIcon(NULL, IDI_APPLICATION);
856     wcx.hCursor = LoadCursor(NULL, IDC_ARROW);
857     wcx.hbrBackground = GetStockObject(WHITE_BRUSH);
858     wcx.lpszClassName = "TestDialog";
859     wcx.lpszMenuName =  "TestDialog";
860     wcx.hIconSm = LoadImage(hInstance, MAKEINTRESOURCE(5), IMAGE_ICON,
861         GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON),
862         LR_DEFAULTCOLOR);
863
864     atom = RegisterClassEx(&wcx);
865     ok(atom != 0, "RegisterClassEx returned 0\n");
866
867     return atom;
868 }
869
870 /* test registering a dialog box created by using the CLASS directive in a
871    resource file, then test creating the dialog using CreateDialogParam. */
872 static void CreateDialogParamTest(HINSTANCE hInstance)
873 {
874     HWND hWndMain;
875
876     if (RegisterTestDialog(hInstance))
877     {
878         hWndMain = CreateDialogParam(hInstance, "CLASS_TEST_DIALOG", NULL, 0, 0);
879         ok(hWndMain != NULL, "CreateDialogParam returned NULL\n");
880         ShowWindow(hWndMain, SW_SHOW);
881         DestroyWindow(hWndMain);
882     }
883 }
884
885 static const struct
886 {
887     const char name[9];
888     int value;
889     int badvalue;
890 } extra_values[] =
891 {
892     {"#32770",30,30}, /* Dialog */
893 #ifdef _WIN64
894     {"Edit",8,8},
895 #else
896     {"Edit",6,8},     /* Windows XP 64-bit returns 8 also to 32-bit applications */
897 #endif
898 };
899
900 static void test_extra_values(void)
901 {
902     int i;
903     for(i=0; i< sizeof(extra_values)/sizeof(extra_values[0]); i++)
904     {
905         WNDCLASSEX wcx;
906         BOOL ret = GetClassInfoEx(NULL,extra_values[i].name,&wcx);
907
908         ok( ret, "GetClassInfo (0) failed for global class %s\n", extra_values[i].name);
909         if (!ret) continue;
910         ok(extra_values[i].value == wcx.cbWndExtra || broken(extra_values[i].badvalue == wcx.cbWndExtra),
911            "expected %d, got %d\n", extra_values[i].value, wcx.cbWndExtra);
912     }
913 }
914
915 static void test_GetClassInfo(void)
916 {
917     static const WCHAR staticW[] = {'s','t','a','t','i','c',0};
918     WNDCLASSA wc;
919     WNDCLASSEXA wcx;
920     BOOL ret;
921
922     SetLastError(0xdeadbeef);
923     ret = GetClassInfoA(0, "static", &wc);
924     ok(ret, "GetClassInfoA() error %d\n", GetLastError());
925
926 if (0) { /* crashes under XP */
927     SetLastError(0xdeadbeef);
928     ret = GetClassInfoA(0, "static", NULL);
929     ok(ret, "GetClassInfoA() error %d\n", GetLastError());
930
931     SetLastError(0xdeadbeef);
932     ret = GetClassInfoW(0, staticW, NULL);
933     ok(ret, "GetClassInfoW() error %d\n", GetLastError());
934 }
935
936     wcx.cbSize = sizeof(wcx);
937     SetLastError(0xdeadbeef);
938     ret = GetClassInfoExA(0, "static", &wcx);
939     ok(ret, "GetClassInfoExA() error %d\n", GetLastError());
940
941     SetLastError(0xdeadbeef);
942     ret = GetClassInfoExA(0, "static", NULL);
943     ok(!ret, "GetClassInfoExA() should fail\n");
944     ok(GetLastError() == ERROR_NOACCESS ||
945        broken(GetLastError() == 0xdeadbeef), /* win9x */
946        "expected ERROR_NOACCESS, got %d\n", GetLastError());
947
948     SetLastError(0xdeadbeef);
949     ret = GetClassInfoExW(0, staticW, NULL);
950     ok(!ret, "GetClassInfoExW() should fail\n");
951     ok(GetLastError() == ERROR_NOACCESS ||
952        broken(GetLastError() == 0xdeadbeef) /* NT4 */ ||
953        broken(GetLastError() == ERROR_CALL_NOT_IMPLEMENTED), /* win9x */
954        "expected ERROR_NOACCESS, got %d\n", GetLastError());
955
956     wcx.cbSize = 0;
957     SetLastError(0xdeadbeef);
958     ret = GetClassInfoExA(0, "static", &wcx);
959     ok(ret, "GetClassInfoExA() error %d\n", GetLastError());
960     ok(wcx.cbSize == 0, "expected 0, got %u\n", wcx.cbSize);
961
962     wcx.cbSize = sizeof(wcx) - 1;
963     SetLastError(0xdeadbeef);
964     ret = GetClassInfoExA(0, "static", &wcx);
965     ok(ret, "GetClassInfoExA() error %d\n", GetLastError());
966     ok(wcx.cbSize == sizeof(wcx) - 1, "expected sizeof(wcx)-1, got %u\n", wcx.cbSize);
967
968     wcx.cbSize = sizeof(wcx) + 1;
969     SetLastError(0xdeadbeef);
970     ret = GetClassInfoExA(0, "static", &wcx);
971     ok(ret, "GetClassInfoExA() error %d\n", GetLastError());
972     ok(wcx.cbSize == sizeof(wcx) + 1, "expected sizeof(wcx)+1, got %u\n", wcx.cbSize);
973 }
974
975 START_TEST(class)
976 {
977     HANDLE hInstance = GetModuleHandleA( NULL );
978
979     test_GetClassInfo();
980     test_extra_values();
981
982     if (!GetModuleHandleW(0))
983     {
984         trace("Class test is incompatible with Win9x implementation, skipping\n");
985         return;
986     }
987
988     ClassTest(hInstance,FALSE);
989     ClassTest(hInstance,TRUE);
990     CreateDialogParamTest(hInstance);
991     test_styles();
992     test_builtinproc();
993
994     /* this test unregisters the Button class so it should be executed at the end */
995     test_instances();
996 }