Re: Win32Bug
- Posted by Robert Craig <rds at EMAIL.MSN.COM> Nov 18, 1998
- 646 views
I've finally solved the Win32 bug. It all comes down to one small mistake in Win32Lib.ew -- Type PAINTSTRUCT psHdc = allot( Long ), psErase = allot( Long ), psPaintRect = allot( SIZEOF_RECT ), -- 16 bytes psRestore = allot( Long ), psIncUpdate = allot( Long ), psRgbReserved = allot( Byte ), <----- !!! SIZEOF_PAINTSTRUCT = allotted_size(), SIZEOF_PAINTSTRUCT is set to 33 bytes. This is wrong. According to Petzold Chapter 3, a PAINTSTRUCT is defined as: typedef struct tagPAINTSTRUCT { HDC hdc; BOOL fErase; RECT rcPaint; // 16 bytes BOOL fRestore; BOOL fIncUpdate; BYTE rgbReserved[32]; } PAINTSTRUCT; where I assume BOOL and HDC are 4 bytes. The problem is that rgbReserved is 32 bytes, not 1. I changed the last line to SIZEOF_PAINTSTRUCT = allotted_size() + 32, and now everything works. (I guess +31 would work too.) I ran Win32Lib using safe.e in place of machine.e and nothing illegal was detected, so I assume that Windows is storing stuff into the rgbReserved area, not David. This bug actually happens in almost all Win32Lib programs, it's just that the storage block that comes after the paint structure is rarely critical. When I ran the Win32Lib demo programs using my debugging version of exw (loaded with extra sanity checks), heap corruption was detected in almost all cases i.e. an allocated block of memory had been scribbled on. The programs reported by Ad Rienks work now. The 12-character thing was just a coincidence. I guess it made the heap corruption evident. I ran through the full set of demo programs in Win32Lib again, and they all work flawlessly now, even with safe.e and the debugging version of exw. Regards, Rob Craig Rapid Deployment Software http://members.aol.com/FilesEu/