Solved

Select language column from resource files

Posted on 2004-10-07
6
392 Views
Last Modified: 2010-05-18
Hi I use a resource file for the labels on my form, default it selects english because my windows XP version is English. I have a Dutch customer that wants to see the texts in Dutch but he has an English version of windows xp. Is there a way to select the Dutch column/strings on an English system. Any help would be appreciated.

Thanks in advance
0
Comment
Question by:Victoria_
  • 2
6 Comments
 
LVL 8

Expert Comment

by:mladenovicz
ID: 12248374
I am not sure, but I think that you have to change your regional settings to Dutch. After that application will use Dutch column instead of English
0
 
LVL 17

Accepted Solution

by:
zzzzzooc earned 333 total points
ID: 12258025
You can select which language of the resource to load with FindResourceEx(). Of course, that means manually loading and parsing the segment-blocks for string resources but.. :P It worked fine in my testing but will probably need modifications to display some languages.

Form1:
----------------------
Option Explicit

Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long
Private Declare Function LoadLibraryEx Lib "kernel32" Alias "LoadLibraryExA" (ByVal lpLibFileName As String, ByVal hFile As Long, ByVal dwFlags As Long) As Long
Private Declare Function SizeofResource Lib "kernel32" (ByVal hInstance As Long, ByVal hResInfo As Long) As Long
Private Declare Function FindResourceEx Lib "kernel32" Alias "FindResourceExA" (ByVal hModule As Long, ByVal lpType As Long, ByVal lpName As Long, ByVal wLanguage As Long) As Long
Private Declare Function LoadResource Lib "kernel32" (ByVal hInstance As Long, ByVal hResInfo As Long) As Long
Private Declare Function LockResource Lib "kernel32" (ByVal hResData As Long) As Long
Private Declare Function FindResource Lib "kernel32" Alias "FindResourceA" (ByVal hInstance As Long, ByVal lpName As Long, ByVal lpType As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (ByRef lpDest As Any, ByRef lpSource As Any, ByVal nCount As Long)

Private Const LANG_ENGLISH = &H9
Private Const LANG_DUTCH = &H13
Private Const LANG_GERMAN = &H7
Private Const SUBLANG_DUTCH = &H1
Private Const SUBLANG_ENGLISH_US = &H1
Private Const SUBLANG_GERMAN = &H1
Private Const LOAD_LIBRARY_AS_DATAFILE = &H2
Private Const RT_STRING = 6
Private Sub Form_Load()
    Dim strString As String
    'Get the GERMAN string with the ID of "103"
    strString = LoadStringEx("c:\project1.exe", "103", LANG_GERMAN, SUBLANG_GERMAN)
    If strString <> vbNullString Then
        Call MsgBox(strString)
    End If
    'Get the ENGLISH string with the ID of "103"
    strString = LoadStringEx("c:\project1.exe", "103", LANG_ENGLISH, SUBLANG_ENGLISH_US)
    If strString <> vbNullString Then
        Call MsgBox(strString)
    End If
End Sub
Private Function LoadStringEx(ByVal strModule As String, ByVal lngStringID As String, ByVal lngLanguage As Long, lngSubLanguage As Long)
    Dim lngLibH As Long
    Dim lngResInfo As Long, lngResH As Long
    Dim lngResPtr As Long, lngResLen As Long, strResBuff As String
    Dim intLoop As Integer, bytLen As Byte, lngPos As Long
    lngLibH = LoadLibraryEx(strModule, 0, LOAD_LIBRARY_AS_DATAFILE)
    If lngLibH <> 0 Then
        lngResInfo = FindResourceEx(lngLibH, RT_STRING, (lngStringID \ 16) + 1, MAKELANGID(lngLanguage, lngSubLanguage))
        If lngResInfo <> 0 Then
            lngResH = LoadResource(lngLibH, lngResInfo)
            If lngResH <> 0 Then
                lngResPtr = LockResource(lngResH)
                If lngResPtr <> 0 Then
                    lngResLen = SizeofResource(lngLibH, lngResInfo)
                    strResBuff = Space(lngResLen)
                    Call CopyMemory(ByVal StrPtr(strResBuff), ByVal lngResPtr, lngResLen)
                    lngPos = 1
                    For intLoop = 0 To 15
                        bytLen = Asc(Mid(strResBuff, lngPos, 1))
                        If bytLen Then
                            If intLoop = (lngStringID Mod 16) Then
                                LoadStringEx = Mid(strResBuff, lngPos + 1, bytLen)
                                Exit For
                            Else
                                lngPos = lngPos + bytLen + 1
                            End If
                        Else
                            lngPos = lngPos + 1
                        End If
                    Next intLoop
                End If
            End If
        End If
        Call FreeLibrary(lngLibH)
    End If
End Function
Private Function MAKELANGID(ByVal p As Integer, ByVal s As Integer) As Long
    MAKELANGID = (s * 1024) Or p
End Function
0
 
LVL 17

Expert Comment

by:zzzzzooc
ID: 12561694
Suggestion: Accept zzzzzooc
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question