?
Solved

Select language column from resource files

Posted on 2004-10-07
6
Medium Priority
?
406 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 1332 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
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…
Suggested Courses
Course of the Month11 days, 22 hours left to enroll

752 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