|
From: Per W. <pw...@ia...> - 2005-08-18 18:53:33
|
One thing to note about the use of a number of Windows structures. The xx.cbSize =3D sizeof(xx) code is used to tell the OS which version of the header files and hence which version of the structure that was used when compiling the application. This allows M$ to later add more fields to the end of the structure and Windows can then support extended behaviour for newer applications that knows about these extra fields. However, if M$ do add more fields and you recompile your code using the newer header files, the chSize field will be set to the correspondingly larger value. Your code will NOT supply any value to these new fields, since you only assign values to fields you know about. In short, a later recompilation of the application after upgrading the compiler environments may result in a badly failing application. To make sure that the cbSize versioning method works, you should _allways_ perform a: memset(&l_Class,0,sizeof(l_Class)); or - since this is a Windows application - do a: ZeroMemory(&l_Class,sizeof(l_Class)); M$ will always make sure that when they add new fields to the structures, the behaviour of the application is unchanged if all the new fields are zeroed. If one or more of them are not zero, Windows will assume that you know about them and have specifically initialized them in preparation to get the benefits of the extended behaviour. Once more - never use a cbSize-type of structure without zeroing the structure first. See it as a breach of contract between the application and the OS. /Per W On Wed, 17 Aug 2005, ZATTI Alessio Consultant wrote: > I think that you have problems when you call RegisterClassEx, right? What= 's the error code that return from GetLastError? > Try to modify your code like below: > > l_Class.hInstance =3D GetModuleHandle(NULL); > l_Class.cbSize =09 =3D sizeof( WNDCLASSEX ); > l_Class.style =3D CS_HREDRAW | CS_VREDRAW; > l_Class.lpszClassName =3D "WindowsApp"; > l_Class.lpfnWndProc =3D WindowProcedure; > l_Class.hbrBackground =3D (HBRUSH) COLOR_BACKGROUND; > l_Class.hCursor =3D NULL; > l_Class.hIcon =3D NULL; > l_Class.hIconSm =3D NULL; > l_Class.lpszMenuName =3D NULL; > l_Class.cbClsExtra =3D 0; > l_Class.cbWndExtra =3D 0; > > > Regards, Ale > > -----Messaggio originale----- > Da: dev...@li... > [mailto:dev...@li...]Per conto di Noorez > Kassam > Inviato: mercoled=EC 17 agosto 2005 5.47 > A: dev...@li... > Oggetto: [Dev-C++] Window Class Error > > > WNDCLASSEX l_Class; > l_Class.cbSize =3D sizeof( WNDCLASSEX ); > l_Class.style =3D 0; > l_Class.lpszClassName =3D "WindowsApp"; > l_Class.lpfnWndProc =3D WindowProcedure; > l_Class.hbrBackground =3D NULL; > l_Class.hCursor =3D NULL; > l_Class.hIcon =3D NULL; > l_Class.hIconSm =3D NULL; > l_Class.lpszMenuName =3D NULL; > l_Class.cbClsExtra =3D 0; > l_Class.cbWndExtra =3D 0; > > This is not working, what am I doing wrong? > > _________________________________________________________________ |