Solved

How can I load a single string from String Table.

Posted on 2001-06-03
3
256 Views
Last Modified: 2013-12-03
There are a number of string tables for different languages defined in rc file.

LANGUAGE LANG_GERMAN, SUBLANG_DEFAULT    
STRINGTABLE DISCARDABLE
BEGIN
    1 "Suchen"
    2 "Leeren"
END
LANGUAGE LANG_ENGLISH, SUBLANG_DEFAULT    
STRINGTABLE DISCARDABLE
BEGIN
    1 "Search"
    2 "Clear"
END

I wonder how to get a string. I try to find and load resource string using FindResourceEx and LoadResource functions, but LoadResource loads StringTable wholly.
LoadString works fine, but it seems that there is no method to define language...
0
Comment
Question by:Kirill_
[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
3 Comments
 
LVL 1

Expert Comment

by:zx9r
ID: 6151639
Try using the win32 API function call FormatMessage(). If you don't have the msdn ask again and I will post an example.

Good luck :)
0
 
LVL 5

Accepted Solution

by:
robpitt earned 100 total points
ID: 6151741
The only reliable way to do this accross all Windows platforms is to manually load and parse the string table resource.

Alas I couldn't find a link to the data format on MSDN.

Anyway heres some working code instead!



int WINAPI LoadStringEx(HINSTANCE hInst,UINT id,LPSTR pBuffer,int nBufferMax,LANGID langid)
{    
    char* pData;
    HRSRC hrsrc;
    HANDLE hRes;
    int i,index,len;
   
    index=id&15;
    id=1+(id/16);    

    hrsrc=FindResourceEx(hInst,RT_STRING,(LPSTR)id,langid);
    if (!hrsrc) return 0;

    hRes=LoadResource(hInst,hrsrc);
    if (!hRes) return 0;

    pData=(char*)LockResource(hRes);

    for (i=0;i<index;i++)
        pData+=*(LPWORD)pData*2+2;

    len=*(LPWORD)pData;
    pData+=2;

    i=WideCharToMultiByte(0,0,(WCHAR*)pData,len,  pBuffer,nBufferMax,0,0);

    if (len<nBufferMax)        
        pBuffer[len]=0;
    else
        pBuffer[nBufferMax-1]=0;

    FreeResource(hRes);

    return i;
}
0
 

Author Comment

by:Kirill_
ID: 6151889
Robpitt, The best there is!
I considered such method (manually load and parse table),
but I suppose there is another Windows native method...
Also, I had troubles  with resource ID in FindResourceEx.
The answer was in your commment:
index=id&15;
id=1+(id/16);
for (i=0;i<index;i++)
    pData+=*(LPWORD)pData*2+2;

But i still can't find explanation in MSDN about such ID's conversion.

Thanks a lot for assistance. I'll close the answer some day soon accepting your comment as an answer (I just hope somebody will give me a link to MSDN :) )
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

739 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