views:

23

answers:

2

I have an application developted with Visual C++ 2008 Express Edition under Windwos XP, which runs propertly on one computer, where the default langaunge is set to English. However, if run the same application on a different computer with default language German, I run into troubles because a predefined string Infinity is not recoginzed during conversion to double using ToDouble, because on the German platform the string should be Unendlich. In particular the mscorlib throws correctly a FormatException.

How can I force the application to run with the English locale? I could not yet find any option...

Thanks for any hint.

+2  A: 

You can set the current locale to English with:

Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US", false);

That will force US English in the current thread. If you do that in the main Windows Forms thread, then your UI culture will always be English. See http://msdn.microsoft.com/en-us/library/b28bx3bh(v=VS.100).aspx for more info.

As Hans pointed out in his comment, this doesn't affect pool threads and can lead to some hard to find bugs. It turns out that there is no global setting that will make every thread use the culture that you define. If you want that functionality, you'll have to make your own application-wide setting and ensure that all threads use it.

Also good to read would be Globalizing Windows Forms.

Jim Mischel
It doesn't, threadpool threads that run I/O completion calls and what-not will still run in the system language. This can cause very subtle and hard to diagnose bugs. A SortedList suddenly isn't sorted anymore for example.
Hans Passant
Yeah. Let me fix that.
Jim Mischel
Thanks! Too bad that there is no global option. I will have a look a the mentioned links, though.
stefangachter
+1  A: 

Use Convert::ToDouble(str, System::Globalization::CultureInfo::InvariantCulture);

Hans Passant
Thanks, this will solve the problem for the time being...
stefangachter