Microsoft KB Archive/217751

= How To Get the Current User Locale ID in a VB EXE Without Restarting =

Article ID: 217751

Article Last Modified on 7/1/2004

-

APPLIES TO


 * Microsoft Visual Basic 5.0 Learning Edition
 * Microsoft Visual Basic 6.0 Learning Edition
 * Microsoft Visual Basic 5.0 Professional Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 5.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition

-



This article was previously published under Q217751



SUMMARY
The Locale ID (LCID) is a 32-bit value that consists of a language ID plus a sort ID and other reserved bits. A language ID is a 16-bit value consisting of a primary language ID and a secondary language ID. After changes have been made to the Language setting in the Regional Settings applet, it is sometimes necessary to get the current user LCID value either in the IDE or within an application without closing down the application. This can be done by calling GetThreadLocale from within an ActiveX EXE server. The server creates its own thread and, by calling GetThreadLocale, the current value can be obtained.

Without using an out-of-process server, the value obtained by calling GetThreadLocale from within a standard EXE application might not be current. You might also see that the value does not get updated in the IDE.

Some of the API calls that use the LCID as a parameter are GetLocaleInfo, GetTimeFormat, and GetDateFormat.



MORE INFORMATION
To create server and client programs to illustrate this technique, do the following:

Create the ActiveX server to get the current value of the LCID.
 Create a new ActiveX EXE project in Visual Basic. Class1 is created by default.  In the Class Module, Class1, place the following code: Private Declare Function GetThreadLocale Lib "kernel32" As Long Public Function GetLCID As Long GetLCID = GetThreadLocale End Function  Click on the Properties menu and select Project1.Properties. On the General tab, set the Project Name and the description to lcidsrvr. Also on the General tab, set the Threading model to Thread Per Object. Click OK. From the File menu, click on the Make Project1.exe item and enter LCIDsrv as the name of the EXE.</li> Click OK.</li></ol>

Create the client application and run the example.
<ol> Bring up another instance of Visual Basic and create a Standard EXE project. Form1 is created by default.</li> Place a TextBox (Text1) and a CommandButton (Command1) on Form1.</li>  Place the following code in the General Declarations section of Form1: Private Declare Function GetThreadLocale Lib "kernel32" As Long Private Sub Command1_Click Dim LCID As Long Dim oLCID As Object ' Use out of proc server to get LCID in separate thread Set oLCID = CreateObject("lcidsrvr.class1") LCID = oLCID.GetLCID Text1.Text = LCID & " (" & Hex$(LCID) & ")" End Sub </li> Bring up the Regional Settings applet by clicking on the Start button and selecting Settings. Click on Control Panel, and then click on Regional Settings.</li> Set the Language on the Regional Settings tab to English (United States) and click the Apply button. (If the Language is already set to English (United States), leave as is.)</li> Run the application and click Command1. You should see the current value of the LCID appear in the TextBox. For US English, this value is 1033 or 409 hex.</li> Change the Language in Regional Settings to English (United Kingdom) and click the Apply button.</li> Click Command1 and the LCID value displayed in the TextBox is 2057 or 809 hex.</li></ol>

Keywords: kbhowto kbapi kblocalsvr KB217751

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.