Beholder wrote:
I'm trying to call the Windows API's function
GetLocaleInfo but the call fails. Using the GetLastError
function, I get error 126: The specified module could not
be found. Here's my code:
private const int LOCALE_SYSTEM_DEFAULT=0x400;
private const int LOCALE_SDECIMAL=0xE;
[DllImport("kernel32.dll",SetLastError=true)]
private static extern int GetLocaleInfoA(int Locale,int
LCType,string lpLCData,int cchData);
private const Int32 MAX_SYMBOL_LENGTH=4;
Int32 callResult;
String symbol;
symbol=new String(' ',MAX_SYMBOL_LENGTH+1);
callResult=GetLocaleInfoA
(LOCALE_SYSTEM_DEFAULT,LOCALE_SDECIMAL,symbol,symb ol.Length
);
Hi Beholder,
this one worked for me:
[DllImport("kernel32.dll")]
static extern int GetLocaleInfo(uint Locale, uint LCType,
[Out] System.Text.StringBuilder lpLCData, int cchData);
private const uint LOCALE_SYSTEM_DEFAULT=0x400;
private const uint LOCALE_SDECIMAL=0xE;
private string GetInfo(uint lInfo)
{
System.Text.StringBuilder lpLCData = new System.Text.StringBuilder(256);
int ret = GetLocaleInfo(LOCALE_SYSTEM_DEFAULT, lInfo, lpLCData,
lpLCData.Capacity);
if (ret > 0)
{
return lpLCData.ToString().Substring(0, ret -1);
}
return string.Empty;
}
//usage:
private void button1_Click(object sender, System.EventArgs e)
{
MessageBox.Show(GetInfo(LOCALE_SDECIMAL));
}
Cheers
Arne Janning