Search code examples
visual-c++assemblymasmunicode-stringwidechar

Wide-character string literal in MASM?


You use

name DB "Foo",0

to declare name to be the byte-string "Foo".

How do you declare it to be a word-string instead? (i.e. 16 bits per character)

Edit:

I'm looking for a method that works well inside macros, e.g.:

GenerateThunk macro Name
    .code
    &Name& proc public
        push    offset NAME
        jmp     &Name&__actual
    NAME:                               ;          I need something like this,
        &Name&_Name dw "&Name&", 0      ;     <--- but `dw' doesn't work!
    &Name& endp
endm

Solution

  • You could do it with:

    align 2
    name DB "F", 0, "o", 0, "o", 0, 0, 0
    

    depending on the encoding you need.

    Within a macro, you may be able to automate this with the forc macro, something like:

    NAME:
        &Name&_Name
            forc chr,<&Name&>
                byte chr, 0
            endm
            byte 0
    

    I haven't tried this since I don't have access to MASM on my current box, so it may not work.