Solved

Select language column from resource files

Posted on 2004-10-07
6
360 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
Comment Utility
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
Comment Utility
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
Comment Utility
Suggestion: Accept zzzzzooc
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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 process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

762 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

16 Experts available now in Live!

Get 1:1 Help Now