flat assembler
Message board for the users of flat assembler.

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

Author
Thread Post new topic Reply to topic
bitRAKE



Joined: 21 Jul 2003
Posts: 3386
Location: vpcmipstrm
bitRAKE
Code:
STRINGTABLES = 0
macro stringtable name,values&
        local base,size
        name dd RVA base,size,0,0
        base:
        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
        STRINGTABLES = STRINGTABLES + 16
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,
Code:
directory \
        RT_STRING,my_strings,\
        RT_MANIFEST,manifests

resource my_strings,\
        1,LANG_NEUTRAL,str_table0,\
        2,LANG_NEUTRAL,str_table1

resource manifests,\
        1,LANG_ENGLISH+SUBLANG_DEFAULT,manifest

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'
endres    
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:
https://devblogs.microsoft.com/oldnewthing/20040130-00/?p=40813

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
bitRAKE



Joined: 21 Jul 2003
Posts: 3386
Location: vpcmipstrm
bitRAKE
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.
Code:
mov eax,<_R"Application">

btnarr TASKDIALOG_BUTTON BTN_MONKEY,<_R"Monkey">

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:
Code:
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
                                        break
                                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
bitRAKE



Joined: 21 Jul 2003
Posts: 3386
Location: vpcmipstrm
bitRAKE
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:
Code:
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.