Solved

How can I load a single string from String Table.

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

zlib is a free compression library (a DLL) on which the popular gzip utility is built.  In this article, we'll see how to use the zlib functions to compress and decompress data in memory; that is, without needing to use a temporary file.  We'll be c…
As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

929 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

10 Experts available now in Live!

Get 1:1 Help Now