Click here to Skip to main content
15,879,490 members
Articles / Desktop Programming / MFC

XCrashReport : Exception Handling and Crash Reporting - Part 4

Rate me:
Please Sign up or sign in to vote.
4.95/5 (78 votes)
19 Oct 2003CPOL10 min read 647.7K   4.6K   201  
Add basic exception handling and crash reporting to your application
// FormatNumberForLocale.h  Version 1.0
//
// Author:  Hans Dietrich
//          hdietrich2@hotmail.com
//
// This software is released into the public domain.
// You are free to use it in any way you like, except
// that you may not sell this source code.
//
// This software is provided "as is" with no expressed
// or implied warranty.  I accept no liability for any
// damage or loss of business that this software may cause.
//
///////////////////////////////////////////////////////////////////////////////

#ifndef FORMATNUMBERFORLOCALE_H
#define FORMATNUMBERFORLOCALE_H

class CFormatNumberForLocale
{
public:
	CFormatNumberForLocale()
	{

	}

	static CString FormatNumber(LPCTSTR lpszNumber)
	{
		CString str = lpszNumber;

		if (!m_bInitialized)
			InitNumberFormatForLocale();

		TCHAR buf[200];
		if (GetNumberFormat(LOCALE_SYSTEM_DEFAULT, 
							0, 
							lpszNumber, 
							&m_nf, 
							buf, 
							_countof(buf)-2))
		{
			str = buf;
		}

		return str;
	}

protected:

	static void InitNumberFormatForLocale()
	{
		// initialize number format for GetNumberFormat()

		m_nf.NumDigits     = 0;
		m_nf.LeadingZero   = 0;
		m_nf.Grouping      = 3;
		m_nf.lpDecimalSep  = _T(".");
		m_nf.lpThousandSep = _T(",");
		m_nf.NegativeOrder = 1;

		lstrcpy(m_szDecimalSep,  _T("."));
		lstrcpy(m_szThousandSep, _T(","));

		if (GetLocaleInfo(LOCALE_SYSTEM_DEFAULT, LOCALE_SDECIMAL, 
			m_szDecimalSep, _countof(m_szDecimalSep)))
		{
			m_nf.lpDecimalSep = m_szDecimalSep;
		}
		if (GetLocaleInfo(LOCALE_SYSTEM_DEFAULT, LOCALE_STHOUSAND, 
			m_szThousandSep, _countof(m_szThousandSep)))
		{
			m_nf.lpThousandSep = m_szThousandSep;
		}
		m_bInitialized = TRUE;
	}

	static BOOL      m_bInitialized;
	static NUMBERFMT m_nf;
	static TCHAR     m_szThousandSep[20];
	static TCHAR     m_szDecimalSep[20];
};

#endif //FORMATNUMBERFORLOCALE_H

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Hans Dietrich Software
United States United States
I attended St. Michael's College of the University of Toronto, with the intention of becoming a priest. A friend in the University's Computer Science Department got me interested in programming, and I have been hooked ever since.

Recently, I have moved to Los Angeles where I am doing consulting and development work.

For consulting and custom software development, please see www.hdsoft.org.






Comments and Discussions