How to access GetLocaleInfo from C#

2019-08-29 03:52发布

问题:

I'm converting a routine from VB6 (a language I do not know) to C#. In the VB6 code it has . . .

LCID = GetThreadLocale        
rc = GetLocaleInfo(LCID, LOCALE_SDECIMAL, data, dataLen)

So in my C#, in the class body, I've added

[DllImport("kernel32.dll", SetLastError = true)]
static extern int GetThreadLocale();

. . . which seems to allow me to make the first call.

But in Googling GetLocaleInfo() I see conflicting information. On the web, in addition to the plain, vanilla GetLocaleInfo(), there's also :

In http://www.webtropy.com/articles/art9-1.asp?f=GetLocaleInfo it refers to something called GetLocaleInfA().

And in this StackOverflow question Windows: Get LCID from locale string? there's a mention of a GetLocaleInfoEx().

How do I know which one to use, and how do I set it up to be called? (BTW, I'll also need to do the same thing for SetLocaleInfo() .

回答1:

Use the proper .NET Framework method:

http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo.lcid(v=vs.110).aspx

Thread.CurrentThread.CurrentCulture.CultureInfo.LCID;



标签: c# winapi locale