Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Iterate through resource string table

Tags:

c++

c

winapi

I have a string table defined like this in my Win32 app:

STRINGTABLE
BEGIN
    IDS_STRING101           "myString1"
    IDS_STRING102           "myString2"
    IDS_STRING103           "myString3"
END

Since I want all of these strings to be part of an array, is it possible to iterate through this table? Since LoadStringA() requires the macros IDS_STRING101 etc., it seems impossible to iterate through it.

For a practical example, how would I programatically move these strings to an array of strings (char* array in C, std::string array in C++) without using the obvious way of writing a long repetitive code of LoadStringA() calls with the second parameter IDS_STRINGXXX? If possible, I want to be able to add more strings to this table in the future without modifying anything in the code.

like image 972
DarkAtom Avatar asked Feb 17 '26 21:02

DarkAtom


1 Answers

There is no API to enumerate through the individual strings of a string table. You would have to load the entire string table resource as a whole into memory and then parse it manually per the documentation.

A simpler solution would be to just call LoadStringA() in a loop, since your string IDs are sequential, eg:

char myStrings[3][16] = {};
for (int idx = 0; idx < 3; ++idx) {
    LoadStringA(hInstance, IDS_STRING101 + idx, myStrings[idx], 16);
}
like image 123
Remy Lebeau Avatar answered Feb 20 '26 11:02

Remy Lebeau



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!