Microsoft Knowledge Base Email Alertz

KBAlertz.com: Specifying an international setting for Windows that uses a comma (,) as the decimal separator in floating point numbers can cause the following four separate problems when you use the ClassWizard to generate DDV routines for dialog controls.

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]

Search KbAlertz

Advanced Search

Webmasters
Put kbAlertz on your website.
[ Click Here for more! ]





ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
KBAlertz referrals get
** SIX MONTHS FREE **


Community Site



We Send hundreds of thousands of emails using ASP.NET Email


ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
KBAlertz referrals get
** SIX MONTHS FREE **




Mentioned In








Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks




Article ID: 149237 - Last Review: August 18, 2005 - Revision: 1.1

BUG: 4 Class Wizard Problems w/ International System Settings

This article was previously published under Q149237

On This Page

SYMPTOMS

Specifying an international setting for Windows that uses a comma (,) as the decimal separator in floating point numbers can cause the following four separate problems when you use the ClassWizard to generate DDV routines for dialog controls.

NOTE: The four problems are labeled A, B, C, and D in this article. Problem A occurs at execution time. The other three (B, C, and D) occur during development time when using ClassWizard.

  1. The DDV routine will only accept input for floating point numbers that use the period decimal point. Using the comma generates the standard dialog message requesting that you enter a number.
  2. If you attempt to enter a validation range for a floating point number using the period (.) decimal separator (the US standard), Class Wizard generates the following error:
    The argument specified for DDV is not valid.
  3. ClassWizard will accept the comma decimal separator at design time, but when the code is compiled, you may get the following errors:
    - error C2059: syntax error : 'bad suffix on number'
    - error C2146: syntax error : missing ')' before identifier 'f'
    - warning C4244: 'function' : conversion from 'const int' to
    'float', possible loss of data
    - error C2059: syntax error : ')'
  4. If you attempt to bring up Class Wizard on the dialog without modifying the DDV code, you will see the error:
    Parsing error: Expected ")".
    Input line: DDV_MinMaxFloat(pDX, m_MyVar, -3,14000f, 3,14000f);
    The ClassWizard will show no controls or variables for the dialog in its listbox.

CAUSE

  1. The DDX/DDV routines use a C-runtime locale by default. This assumes that the decimal separator is always a period. This is by design.
  2. This behavior is by design. ClassWizard uses the international settings to determine the valid decimal separator.
  3. This behavior is a bug in ClassWizard. Using the comma decimal separator, ClassWizard generates DDV code similar to the following:
          // DDV for a float variable between -3,14 and +3,14.
          DDV_MinMaxFloat(pDX, m_MyVar, -3,14000f, 3,14000f);
    						
    The commas in -3,14000f and 3,14000f are interpreted as parameter separators which makes this line invalid.
  4. This behavior is a side effect of problem B. It can be corrected by using the workaround described in the resolution section.

RESOLUTION

  1. DDX_Text(..., float&) uses the UNICODE version of strtod (tcstod) to convert the number. This is a C run-time function, therefore the C run-time locale is used. If the application calls the setlocale function (as shown below), the local will be synchronized with the system locale, and the DDX_Text call will work as expected. This call to setlocale() should be performed immediately after the application starts, for example in the InitInstance method of the CWinApp derived class.
       #include <locale.h>
    
       CMyApp::InitInstance()
       {
            setlocale( LC_ALL, "" );
            ...
       }
    						
  2. This is by Design. Enter floats using the locale's decimal separator which in this case is a comma.
  3. This problem can also be solved manually by replacing the commas in the DDV function calls with periods as shown here:
       // DDV for a float variable between -3,14 and +3,14.
       DDV_MinMaxFloat(pDX, m_MyVar, -3.14000f, 3.14000f);
    						
  4. After problem C is solved, the DDV macro should be moved out of the ClassWizard brackets or ClassWizard will report an error when it tries to parse the code. This is a related problem in ClassWizard.

    If you do not move the DDV macro, you bring up the same dialog in ClassWizard again, and you examine the validation range for your float variable, the ranges will be shown with the period decimal separator. Choosing OK will once again generate the error:
    The argument specified for DDV is not valid.
    If you need to change the validation ranges, you must manually edit the DDV code again. If the validation ranges are acceptable as entered, choose Cancel on the ClassWizard dialog when prompted with the error message.

STATUS

Problems A and B are by design.

Microsoft has confirmed that problems C and D are bugs in the Microsoft products listed at the beginning of this article.

MORE INFORMATION

The following regional settings taken from the Windows 95 Control Panel applet are affected by these bugs:

  • Basque, Catalan, Danish, Finnish, Icelandic, Indonesian, Swedish
  • Dutch (Belgian and standard)
  • French (Belgian, Canadian, Luxembourg and standard, but NOT Swiss)
  • German (Austrian, Luxembourg and standard, but NOT Liechtenstein or Swiss)
  • Italian (standard, but NOT Swiss)
  • Norwegian (Bokmal and Nynorsk)
  • Portuguese (Brazil and Portugal)
  • Spanish (Argentina, Chile, Modern Sort, Paraguay, Peru, Traditional Sort, Uruguay and Venezuela, but not Colombia, Costa Rica, Dominican Republic, Ecuador, Guatemala, Mexico or Panama)

Steps to Reproduce Problem

  1. Open the Windows Control Panel.

    In Windows 3.X or Windows NT:

    1. Run the International applet.
    2. Change the country setting to Germany.
    In Windows 95:

    1. Run the Regional Settings applet
    2. Change Regional Settings to German (standard)
  2. Create a default AppWizard application.
  3. Add a dialog that contains an edit control.
  4. Bring up Class Wizard and add a Member Variable for the edit control with a Category of value and a type of float.
  5. Enter a validation range containing decimals.
    1. Run the application, and try to enter a float with a decimal point to see problem A.
    2. Enter a validation range using a period decimal separator and try to exit ClassWizard to see problem B.
    3. Enter a validation range using a comma decimal separator and compile to see problem C.
    4. Exit ClassWizard and bring it back up on the same dialog after changing the commas to periods as specified in the resolution of problem D.

APPLIES TO
  • Microsoft Foundation Class Library 4.2
Keywords: 
kbbug kbwizard KB149237
Retired KB ArticleRetired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate

Be the first to leave feedback, to help others about this knowledge base article.

(Optional) Name

(Optional) Public URL Or Email

Comments
No HTML -- Text Only Please