How to access GetLocaleInfo from C#

馋奶兔 提交于 2019-12-12 02:44:50

问题


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;



来源:https://stackoverflow.com/questions/24561364/how-to-access-getlocaleinfo-from-c-sharp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!