Solved

How can I load a single string from String Table.

Posted on 2001-06-03
3
239 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_
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

759 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now