Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using GetLocaleInfoEx to get the regional setings for currency

API Functions

Using GetLocaleInfoEx to get the regional setings for currency

by  vgulielmus  Posted    (Edited  )
GetLocaleInfo and GetLocaleInfoEx can be used to get the local settings for currencies (the ones from Control Panel -> Regional Settings)

Both GetLocaleInfo and GetLocaleInfoEx gives plenty of information. They can be invoked similarly, and gives similar results.
The main difference between the the functions signature is the first parameter. GetLocaleInfo have a LONG parameter, while GetLocaleInfoEx a character parameter.

GetLocaleInfo can be used in Windows XP, Vista and above. GetLocaleInfo tends to become deprecated.
GetLocaleInfoEx can be used in Windows Vista and above, but cannot be used in Windows XP.

GetLocaleInfo provide ASCII results, while GetLocaleInfoEx supports Unicode.
This means many currencies (like English India) can be obtained only with GetLocaleInfoEx.

To get the values for the default settings, the first parameter of GetLocaleInfoEx must be Null.
For other values, use the format <language> - <REGION>, but converted to Unicode
For example
StrConv ("en-AU", 5) + CHR (0)
or
StrConv ("en-US", 5) + CHR (0)

[code Foxpro]Declare INTEGER GetLocaleInfoEx in Win32API String Locale, LONG LCType, STRING @LpLCData, INTEGER cchData

LOCAL LpLCData,cchData,nretval,LPCWSTR
LpLCData = space(255)
cchData = LEN(LpLCData)
nretval = 0

? "get the currency symbol for user default"
LPCWSTR = Null
nretval = GetLocaleInfoEx(LPCWSTR, 0x14, @LpLCData, cchData)
?nretval,LpLCData,TRANSFORM(ASC(SUBSTR(LpLCData,2)),"@0"),TRANSFORM(ASC(LpLCData),"@0") && Euro is Unicode 0x20 0xAC

? "get the currency symbol for UK"
LPCWSTR = STRCONV("en-GB",5)+CHR(0)
nretval = GetLocaleInfoEx(LPCWSTR, 0x14, @LpLCData, cchData)
?nretval,LpLCData,TRANSFORM(ASC(SUBSTR(LpLCData,2)),"@0"),TRANSFORM(ASC(LpLCData),"@0") && pound is Unicode 0x00 0xA3 or ASCII 0xA3

? "currency position"
nretval = GetLocaleInfoEx(Null, 0x1B, @LpLCData, cchData)
?nretval,LpLCData

? "decimal separator"
nretval = GetLocaleInfoEx(Null, 0x16, @LpLCData, cchData)
?nretval,LpLCData

? "thousand separator"
nretval = GetLocaleInfoEx(Null, 0x17, @LpLCData, cchData)
?nretval,LpLCData

? "number of decimals"
nretval = GetLocaleInfoEx(Null, 0x19, @LpLCData, cchData)
?nretval,LpLCData[/code]

http://praisachion.blogspot.ro/2015/06/using-getlocaleinfo-and-getlocaleinfoex.html
http://praisachion.blogspot.ro/2015/06/using-getlocaleinfo-and-getlocaleinfoex_14.html
http://praisachion.blogspot.ro/2015/06/using-getlocaleinfo-and-getlocaleinfoex_79.html

Vilhelm-Ion Praisach
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top