flat assembler
Message board for the users of flat assembler.
Index
> Windows > [fasmg] Useful Resource String Tables: |
Author |
|
bitRAKE 25 Mar 2022, 16:07
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 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 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)/¯ “languages are not safe - uses can be” Bjarne Stroustrup |
|||
25 Mar 2022, 16:07 |
|
bitRAKE 27 Mar 2022, 06:18
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 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 _________________ ¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup |
|||
27 Mar 2022, 06:18 |
|
bitRAKE 29 Mar 2022, 23:40
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) _________________ ¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup |
|||
29 Mar 2022, 23:40 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.