News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Unicode in MasmBasic

Started by jj2007, March 24, 2010, 10:17:51 PM

Previous topic - Next topic

jj2007

After my rant on string tables and EnumResourceNames, and a considerable amount of googling for better solutions, I decided to implement a Res$(ID).

This is now valid Masm32TM code:

invoke MessageBoxW, 0, wChr$("Are you sure?"), wChr$("Write string table to MyStringsUC.txt:"), MB_YESNO
.if eax==IDYES
Open "O", #1, "MyStringsUC.txt"
wPrint #1, wChr$("The current string table:"), wCrLf$
For_ n=1000 To 1020
wPrint #1, wStr$(n), wTb$, wRes$(n), wCrLf$
Next
Close
.endif

... provided you have the latest version of MasmBasic and the following resource file:
QuoteSTRINGTABLE   ; 20 entries, 13312 bytes
BEGIN
   1000,   "This is the first resource string, ID 1000"
   ;    According to my preview, FireFox doesn't like displaying arabic, but copying from a quoted reply seems to work...
   1001,   "Why not an arabic text: ١- أذكر حدثين من الحرب كان لهما تأثير على الرأي العام."
   2000,   "This is the third string, ID 2000 "
   3000,   "String 1003"
   4000,   "String 1004"
   5000,   "String 1005"
...
   19000,   "String 1019"
   20000,   "String 1020"
END

The same works without all the little w prefixes, but the arabic text will be all question marks in the output text file.

jj2007

Version 9w of MasmBasic implements a "wide" Instr, with true Unicode support via LCMapString. Code example:

Quote   .if wInstr(wRes$(101), wRes$(102), 1)   ; 1=case-insensitive, 0 or omitted=case-sensitive
      mov ecx, eax   ; wStr$ will be pushed first, and trashes eax, so we use ecx here
      invoke MessageBoxW, 0, ecx, wStr$("wInstr: %i", edx), MB_OK
   .else
      MsgBox 0, "No match", "Unicode Instr:", MB_OK
   .endif

Options like in the normal Instr_, i.e. 1=case-insensitive, 0 or omitted=case-sensitive; however, the full word mode (+4) is not available.