I searched high and low but could not find Ernie Murphy's macro for unicode strings so I have written another that is working OK but does not do exactly what I need it to do.

USTRING MACRO vname,text
LOCAL label,x
item CATSTR <vname>,< dw >
FORC x, <text>
item CATSTR item,<">,<x>,<",>
item CATSTR item,<0>

USTRING var1, < This is a test >

What I would like to be able to do is control the formatting of the string in the .DATA section with normal quotation marks so that it would be entered in this form.

USTRING var1, " This is a test "

I set up a test piece and could get it to filter out the quotations by doing a comparison,

IF x eq 34
goto label

The result is written correctly but MASM drops an error then for every character generated by the FORC loop.

I would be interested to see if anyone has done a viable UNICODE macro that can handle the format that I am after or alternatively knows how to get around the problem I had with filtering characters.


Posted on 2003-01-08 17:42:48 by hutch--
The errors might result from using reserved words?
USTRING MACRO vname, txt

LOCAL x, item

item TEXTEQU <>

FORC x, <txt>
IFDIF <">, <&x>
item CATSTR item,<">,<x>,<",>

vname dw item 0

USTRING var1, " This is a test "
Posted on 2003-01-08 22:31:28 by bitRAKE

TCHAR macro nam, txt
ifdef _UNICODE_
; do wide char
name db txt, 0
Posted on 2003-01-09 01:41:09 by gfalen
Steve, try my collection of strings macros.
I bet you'll like it.
You can simply define non/labeled non/aligned ansi/unicode text in data or rdata section.
invoke MessageBoxW, NULL, $CTW0("Cool program\nCopyright ? Cool Coder, 2003"), $CTW0("About"), MB_OK

At the top of Strings.mac you will find many examples how to use it.
Posted on 2003-01-09 05:14:41 by Four-F

I searched high and low but could not find Ernie Murphy's macro for unicode strings so I have written another that is working OK but does not do exactly what I need it to do.

The Ernie Murphy's macro for Unicode strings is "colib11\masm32\COM\include\L.inc" file. You can download the whole com package in http://com4me.net/win32asm/fichiers/colib11.zip.

I also attach the code in L.inc here.

; L.inc Macro to produce wide character strings
; revised 2/26/01 complete re-write to simplify
; also add a back the backslash char
; copyright (c) July 30, 2000 Ernest Murphy
; For educational use only. Any commercial re-use only by written license
; Special codes:
; \0 trailing zero
; \| exclamation point '!'
; \n new line (13,10)
; \\ single backslash '\'

wchar typedef word

LOCAL str, chr, flag, cchr
cchr TEXTEQU <>
str TEXTEQU <>
flag TEXTEQU <.>
FORC chr, <&sText>
IFIDN flag, <\> ;; IF flag == '\' we're in control char mode
IFIDN <&chr>, <\> ;; '\\' makes a single backslash
cchr TEXTEQU <"\"> ;; just as in C
IFIDN <&chr>, <|> ;; a pipe gives '!'
cchr TEXTEQU <"!!"> ;; need 2 because of macro alias
IFIDN <&chr>, <n> ;; "n" gives a new line
cchr TEXTEQU <13,10>
IFIDN <&chr>, <0> ;; an "0" (terminating zero)
cchr TEXTEQU <0>
flag TEXTEQU <.>
ELSE ;; ELSE, not in control mode
IFIDN <&chr>, <\> ;; if chr =='\', go to control mode
flag TEXTEQU <\>
cchr TEXTEQU <>
ELSE ;; else must be a regular char
cchr CATSTR <">, <chr>, <">
IFDIF str, <> ;; need a comma before we add new
IFDIF flag, <\>
str CATSTR str, <,>
IFDIF cchr, <> ;; check we don't add a blank
str CATSTR str, &cchr
Posted on 2003-01-09 05:47:18 by yoursguideline

Thanks for the example, the IFDIF was exactly what I needed and I have it working correctly.

Also thanks to everyone else who posted suggestions, I will have a look at the different code as I get time.


Posted on 2003-01-09 08:24:14 by hutch--
Is UNICODE only LATIN chars?
Posted on 2003-01-11 13:22:43 by Nexo

I think UNICODE with its 64k range can do a much wider range of character sets with the emphasis being on character sets like chinese, hebrew, arabic, cyrillic and others that do not fit well into the latin character set.


Posted on 2003-01-11 16:37:22 by hutch--
Ok, hutch--. These macros cant generate UNICODE string. It is generate WORDs ANSI (WIDE) characters string. I never see macro, which can generate UNICODE string. This feature must be supported by assembler, obviously.
Posted on 2003-01-12 02:13:39 by Nexo
Hutch, i guess you dont come by the COM section too often ;)

I just dont like the L.inc so i wrote my own as well about a month earlier. Its pretty ez to use, and can produce alot of raw unicode quickly! Just look at the example ;)

Unicode made E-Z

Posted on 2003-02-05 21:59:03 by NaN
All those macros works properly only with english texts and never with national alphabets. So if you use greek, hungarian, bulgarian etc. u need this API

invoke lstrlen, addr Buf
invoke MultiByteToWideChar, CP_ACP, ; code page
MB_PRECOMPOSED, ; standard conversion
addr Buf, ; input string
eax, ; and it's length
addr Buf1, ; output (Unicode)
1000 ; max length

Posted on 2003-02-20 05:34:11 by Mike
I agree with Nexo, these all macros are about Wide Char, not Unicode.
AFAIK simple use of Unicode with national char sets might be done
with resources.
Posted on 2003-02-28 19:23:28 by The Svin