Solved

How can I load a single string from String Table.

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to use Dotfuscator CE with Visual Studio 2010 Installer? 4 292
SQL to ElasticSearch Query 1 636
wordpress limitations 4 115
SSIS 2010 Convert to SSIS 2013 On Different Box 3 58
This article shows a few slightly more advanced techniques for Windows 7 gadget programming, including how to save and restore user settings for your gadget and how to populate the "details" panel that is displayed in the Windows 7 gadget gallery.  …
This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
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…

776 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