flat assembler
Message board for the users of flat assembler.

Index > Windows > [fasmg] Useful Resource String Tables:

Thread Post new topic Reply to topic

Joined: 21 Jul 2003
Posts: 3386
Location: vpcmipstrm
macro stringtable name,values&
        local base,size
        name dd RVA base,size,0,0
        iterate <sid,quoted>,values
                if %% > 16 & %% = %
                        err 'stringtable: ',`name,' has more than 16 entries'
                end if
                sid := % - 1 + STRINGTABLES
                dw (@f - $)/2-1
                du quoted
        end iterate
        size := $ - base
end macro    
This has been tested. Several other versions appear on this board that are incorrect (including my own previous comments). The problem stems from many APIs not allowing a resource ID of zero. Yet, there is a resource string zero!

Since we do not control the string IDs from the numbers, but rather the position within the table; it's beneficial to create the macro that works in this way - defining the symbol values from the table creation. Typically, we do not care what their value is - just that they are unique.

I did consider also producing the directory entry and allow defining a long table of strings. That approach provides very little benefit and two negatives: hiding the structure of a resource file and hiding the language specification. Whereas this just hides the structure of the string resource table.

Multi-table example to make use clear,
directory \

resource my_strings,\

resource manifests,\

stringtable str_table0,\ ; ids 00 - 0F
        IDS_ZERO,       "Zero isn't accepted by many APIs!",\
        IDS_1,  "1",\
        IDS_2,  "2",\
        IDS_3,  "3",\
        IDS_4,  "4",\
        IDS_5,  "5",\
        IDS_6,  "6",\
        IDS_7,  "7",\
        IDS_8,  "8",\
        IDS_9,  "9",\
        IDS_a,  "A",\
        IDS_b,  "B",\
        IDS_c,  "C",\
        IDS_d,  "D",\
        IDS_e,  "E",\
        IDS_f,  "F"

stringtable str_table1,\ ; ids 10 - 1F
        IDS_10, "10",\
        IDS_11, "11",\
        IDS_12, "12",\
        IDS_13, "13",\
        IDS_14, "14",\
        IDS_15, "15"

resdata manifest
        file 'manifest.minimal.xml'
The directory entry IDs are only needed if manually loading resources, but have no use if the string IDs are just going to be used in other APIs. Anyway, the table ID is always (string ID shr 4)+1.

It's nice when it works and it's easy to move strings around with no other changes. Yet, there is still the flexibility to tune ID numbers if I want.

Also, it completely aligns with Raymond Chen's explanation:

When can resource string IDs be used?
Any time MAKEINTRESOURCE() is accepted for a string, within the documentation.

¯\(°_o)/¯ unlicense.org
Post 25 Mar 2022, 16:07
View user's profile Send private message Visit poster's website Reply with quote

Joined: 21 Jul 2003
Posts: 3386
Location: vpcmipstrm
Another problem with automatically gathering the resource strings and POSTPONE'ing the generation of tables is that the size of the data changes based on where it's needed. Resource string IDs in other resource templates are DWORDs. Yet, within code the resource IDs are the size of pointers. Then there are structures like TASKDIALOG_BUTTON which are also accept pointer size resource string IDs.

Ideally, super-lazy mode would consist of a universal syntax for resource strings that could be used in code, as well as resource and structure definitions.
mov eax,<_R"Application">


dialogitem 'BUTTON',<_R"Monkey">,BTN_MONKEY,188,12,60,14,WS_VISIBLE+WS_TABSTOP    
The programmer wouldn't manage ID names in this "high-level" modality.

I'm not aware of resource strings being used for non-string data, by standard APIs. It is possible though - they can consist of anything.

String gathering is just an adaptation of GLOBSTR macro:
struc RSTRING value&
        local found,sid,O,r,ri,x,xi
        virtual at 0
                du value
                xi := $
                load x:$-$$ from $$
        end virtual
        found = 0
        virtual RSTRING.buffer
                sid = 0
                O = 0
                while O < $
                        load ri:2 from O
                        if ri = xi
                                load r:ri from O+2
                                if r = x
                                        found = 1
                                        . = sid
                                end if
                        end if
                        O = O + ri + 2
                        sid = sid + 1
                end while
                if ~ found
                        . = sid
                        dw xi
                        db x
                end if
        end virtual
end struc    
Output is a little more complex - as the tables need to be batched.

¯\(°_o)/¯ unlicense.org
Post 27 Mar 2022, 06:18
View user's profile Send private message Visit poster's website Reply with quote

Joined: 21 Jul 2003
Posts: 3386
Location: vpcmipstrm
I've refactor my recent TaskDialog example to use resource ids instead of string pointers. The diff is a good example of how to use the feature and the reduction in code resulting from the change. For APIs that accept resource IDs it's almost completely automatic. Yet, we still need to be aware of data type change - working with resource ID words and not pointers.

I have yet to test in 32-bit, but there is no reason it shouldn't work. I have tested the following corner cases:
zero strings
strings without output
duplicate strings
one partial table
one complete table
multiple tables (w/ and w/o partial)    
Doesn't work with dialog items, yet.

¯\(°_o)/¯ unlicense.org
Post 29 Mar 2022, 23:40
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum

Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.