🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.internationalization
Article #671

Stringtables with multiple languages

#671
From: Stefan Meyer
Date: Sun, 11 Aug 2002 13:24
94 lines
3114 bytes
Hi!

In order to implement multiple languages in my application,
I'm using stringtable resources like this:

**********

STRINGTABLE LANGUAGE LANG_GERMAN, SUBLANG_NEUTRAL
BEGIN

  START_EDITOR       "&Editor";
  START_VERWERFEN    "&Verwerfen";

END

STRINGTABLE LANGUAGE LANG_ENGLISH, SUBLANG_NEUTRAL
BEGIN

  START_EDITOR       "&Editor";
  START_VERWERFEN    "&Discard";

END

**********

I've found a piece of code on MSDN which works:

**********

wchar_t* GetWideStringFromStringTable(UINT uStringID, int iLanguage)
{
   wchar_t   *pwchMem, *pwchCur;
   UINT      idRsrcBlk = (uStringID >> 4) + 1;
   int       strIndex  = uStringID % 16;
   HINSTANCE hModule = NULL;
   HRSRC     hResource = NULL;

   hResource = FindResourceEx(HInstance,
                              RT_STRING,
                              MAKEINTRESOURCE(idRsrcBlk),
                              MAKELANGID(iLanguage, SUBLANG_NEUTRAL));

   if (hResource != NULL)
   {
      pwchMem = (wchar_t*) LoadResource(hModule, hResource);

      if (pwchMem != NULL)
      {
         pwchCur = pwchMem;

         for (int i = 0; i < 16; i++)
         {
            if (*pwchCur)
            {
               int cchString = *pwchCur;  // String size in characters.
               pwchCur++;

               if (i == strIndex)
               {
                  // The string has been found in the string table.

                  wchar_t *pwchTemp = new wchar_t[cchString];
                  wcsncpy(pwchTemp, pwchCur, cchString);
                  pwchTemp[cchString] = '\0';

                  return pwchTemp;
               }

               pwchCur += cchString;
            }
            else
               pwchCur++;
         }
      }
   }

   return NULL;
}

**********

The problem: When I switch languages during the run of my
application, I sometimes get the error "illegal pointer operation"
or the application throws an "EExternalException".

Could anybody please tell me why?

Additional question: In the code above I replaced "wchar_t"
with "char" and "wcsncpy" with "strncpy", but then the code
won't work any more. Why?

Thanx alot

Stefan (stem @ abi-selb.de)
Technical Details
Message-ID: <aj5oq7$18ki78$1@ID-37110.news.dfncis.de>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-01!sn-xit-04!supernews.com!news.maxwell.syr.edu!fu-berlin.de!uni-berlin.de!affa1.pppool.DE!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10297d,a4a2f5e4748fea3c,start
X-Google-Attributes: gid10297d,public
X-Google-ArrivalTime: 2002-08-11 06:32:22 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-01!sn-xit-04!supernews.com!news.maxwell.syr.edu!fu-berlin.de!uni-berlin.de!affa1.pppool.DE!not-for-mail
From: "Stefan Meyer" <stem@stem.de>
Newsgroups: borland.public.cppbuilder.internationalization
Subject: Stringtables with multiple languages
Date: Sun, 11 Aug 2002 15:24:51 +0200
Lines: 96
Message-ID: <aj5oq7$18ki78$1@ID-37110.news.dfncis.de>
NNTP-Posting-Host: affa1.pppool.de (213.6.255.161)
X-Trace: fu-berlin.de 1029072520 42617064 213.6.255.161 (16 [37110])
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.50.4522.1200
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200