?
Solved

How can I load a single string from String Table.

Posted on 2001-06-03
3
Medium Priority
?
258 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 400 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
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…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

770 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