Solved

Select language column from resource files

Posted on 2004-10-07
6
399 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_
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

705 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