Solved

Select language column from resource files

Posted on 2004-10-07
6
370 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

896 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now