Answered by:
Changing OS Language SetLocaleInfo function

Question
-
I need to change the OS language in my C# application by importing the native SetLocale function.
[
DllImport("kernel32.dll", CharSet = CharSet
.Auto)]
public static extern int SetLocaleInfo(int locale, int lcType, String
lplcData);
However, I am no able to figure out the value to be passed to LCTYPE parameter and lplcData parameter.
My call to the function is:
int
lcid = GetSystemDefaultLCID();
int result = SetLocaleInfo(lcid, 0x00000001, "409");
Am i making the right call? result has a value 0 indicating failure.
Please help me out with this. What should the values to the three arguments be?
Wednesday, November 30, 2011 6:10 AM
Answers
-
- Marked as answer by Lie YouModerator Monday, December 5, 2011 2:58 AM
Wednesday, November 30, 2011 6:36 AM -
Try this below code:class Sample{public const int LOCALE_SSHORTDATE = 0x1F;public const int LOCALE_SDATE = 0x1D;[DllImport("kernel32.dll")]static extern bool SetLocaleInfo(uint Locale, uint LCType, string lpLCData);[DllImport("kernel32.dll")]private static extern uint GetUserDefaultLCID();public static void Main(string[] args){uint lngLCID;lngLCID = GetUserDefaultLCID();bool ret1 = SetLocaleInfo(lngLCID, LOCALE_SSHORTDATE, "yyyy/MMM/dd");bool ret2 = SetLocaleInfo(lngLCID, LOCALE_SDATE, "/");const int LOCALE_ILANGUAGE = 0x1;bool ret3 = SetLocaleInfo(lngLCID, LOCALE_ILANGUAGE, "0x401");Console.ReadLine();}}
- Proposed as answer by RAJESH_BALA Wednesday, November 30, 2011 7:35 AM
- Marked as answer by Lie YouModerator Monday, December 5, 2011 2:58 AM
Wednesday, November 30, 2011 7:35 AM
All replies
-
- Marked as answer by Lie YouModerator Monday, December 5, 2011 2:58 AM
Wednesday, November 30, 2011 6:36 AM -
Try this below code:class Sample{public const int LOCALE_SSHORTDATE = 0x1F;public const int LOCALE_SDATE = 0x1D;[DllImport("kernel32.dll")]static extern bool SetLocaleInfo(uint Locale, uint LCType, string lpLCData);[DllImport("kernel32.dll")]private static extern uint GetUserDefaultLCID();public static void Main(string[] args){uint lngLCID;lngLCID = GetUserDefaultLCID();bool ret1 = SetLocaleInfo(lngLCID, LOCALE_SSHORTDATE, "yyyy/MMM/dd");bool ret2 = SetLocaleInfo(lngLCID, LOCALE_SDATE, "/");const int LOCALE_ILANGUAGE = 0x1;bool ret3 = SetLocaleInfo(lngLCID, LOCALE_ILANGUAGE, "0x401");Console.ReadLine();}}
- Proposed as answer by RAJESH_BALA Wednesday, November 30, 2011 7:35 AM
- Marked as answer by Lie YouModerator Monday, December 5, 2011 2:58 AM
Wednesday, November 30, 2011 7:35 AM