February Fourteenth 2002 From: Bob Zale, President PowerBASIC, Inc. PowerBASIC Gazette #25 ====================== *** Caution... Windows Bug *** Welcome to the next Gazette from PowerBASIC! Today, we'd like to bring you a cautionary note about a fairly serious bug in Windows. But with an easy workaround, of course. Please read on... We've confirmed that at least some versions of Win2000 (perhaps some other versions of Windows, as well) exhibit a very serious flaw which can affect the operation of the numeric coprocessor. The Windows API function MessageBox(), whenever and wherever it is executed, may alter both the state and the contents of the Numeric Processor (the 80x87). Of course, internally, the PowerBASIC MSGBOX Statement and Function both call the WinAPI MessageBox(), with potentially fatal side effects for your application. This problem affects every programming language, not just PowerBASIC. Whenever MessageBox() is executed on one of the flawed systems, all internal registers are reset to the value zero, and the precision level for all calculations is reset to 54-bits of mantissa (which is equivalent to double precision). This is a blatant violation of all of "The Rules" of operating system behavior, and will hopefully be corrected by Microsoft in the near future. So just what does this mean to you? In some cases, nothing. If you aren't using extended precision variables in your program, you only need 54-bits of mantissa, rather than 64. That's frequently not a big deal. But the other part of the problem could be much more serious. Frequently, high level programming languages like PowerBASIC need to store one or more temporary values. The numeric processor registers are the perfect choice, because of the optimum speed, so most of the better compilers use this technique often. If these values (or even floating point register variables) are unilaterally reset to zero, it bodes disaster for your program. Is it possible to protect yourself? Fortunately, the answer is a resounding "Yes". Here's the technique to use... We suggest the following: Create a separate, user-written function which encapsulates the MSGBOX statement and function, and resets the NPX Control Word to the correct default bit mask. A ready-to-use sample function follows in this text. Include this function in every program which uses a MSGBOX statement or function. Then, search through your source, and change every MSGBOX reference to call this new, user-written function instead. That's all there is to it with PowerBASIC, though we can't guarantee this level of functionality with other compilers. Why is it solved so easily with PowerBASIC? Well, for utmost speed and efficiency, whenever PowerBASIC code calls another Sub or Function, it automatically saves off and restores any temporary values stored in numeric registers. Since there are only eight numeric registers in total, the target function should have all of them available for optimization needs. If not, the compiled executable code might have to make some serious compromises. Of course, not every compiler offers this level of safety and efficiency, but we're pleased to confirm this fact about all current PowerBASIC Compilers. If you will follow this technique as outlined, it should alleviate the problem immediately. Function MesgBox(Mesg$, MesgStyle&, MesgTitle$) as Long #REGISTER NONE DIM CtrlWrd% MesgBox = MSGBOX(Mesg$, MesgStyle&, MesgTitle$) CtrlWrd% = &B0001001100111111 ASM FLDCW CtrlWrd% ; this guarantees extended precision End Function =================================================================== Order online at https://www.powerbasic.com/shop/ or just send email with all pertinent information to sales@powerbasic.com We'll take it from there! ------------------------------------------------------------------- Most PowerBASIC products (those without printed books) can now be delivered by electronic mail. No wait for a package to arrive... No high shipping costs... For just $6 per order, no matter how many products, we'll deliver directly to your computer. If you're outside the U.S., savings might be greater. You won't pay taxes or duties to a freight company or postal service, because they aren't involved in the delivery. Check your tax code to be sure, but some countries charge no tax at all on transactions of this type. It could just be your lucky day! ==================================================================== Is your PowerBASIC Gazette Electronic Edition subscription coming to you at home or work? If you don't want to miss a single issue, why not subscribe from both email addresses? Send your subscription request to email@powerbasic.com and please include your name and all email addresses you'd like to add as well as your Zip or Postal Code. If you know someone else who would enjoy this newsletter please forward a copy to them so they can subscribe. ==================================================================== All contents Copyright (c) 2002-2009 PowerBASIC Inc All Rights Reserved. PowerBASIC is a registered trademark of PowerBASIC, Inc. PB/CC, PB/DLL, and PowerTREE are trademarks of PowerBASIC Inc. Other names are trademarks or registered trademarks of their owners. ==================================================================== PowerBASIC Gazette - Electronic Edition Volume 1 - Issue 25 PowerBASIC, Inc. (888) 659-8000 Sales 2061 Englewood Road (941) 473-7300 Voice Englewood, FL 34223 (941) 681-3100 Fax Visit us on the World Wide Web at www.powerbasic.com Email Sales: sales@powerbasic.com This newsletter is only sent to email addresses in our subscription list. If you have received this newsletter by mistake or no longer wish to receive it, please send a simple unsubscribe request to support@powerbasic.com with your name and zip/postal code. This newsletter is best viewed with a fixed-width font. ====================================================================