The MASM Forum

64 bit assembler => 64 bit assembler. Conceptual Issues => Topic started by: morgot on July 02, 2021, 08:14:44 AM

Title: How to use utf-16 strings ?
Post by: morgot on July 02, 2021, 08:14:44 AM
Hello,
In 32 bit masm was good macro uni$, but in 64 bit this not exists.

I see 2 variants:
1. str1 dw 's','t','r','o','k','a',0,0
2. use TimoVJ program to convert via str dw 73h,74h,72h,6Fh,6Bh,61h,0

but maybe someone wrote simpler macros?
Title: Re: How to use utf-16 strings ?
Post by: HSE on July 02, 2021, 09:00:17 AM
Hi morgot,

In code section perhaps work: uni$ MACRO RegAux, arglist:VARARG
      LOCAL DATA@NAME
      WSTR DATA@NAME,arglist
      lea &RegAux, DATA@NAME
      EXITM <&RegAux>
    ENDM


Use?:uni$(rax, stroka)
Title: Re: How to use utf-16 strings ?
Post by: morgot on July 03, 2021, 12:15:57 AM
Don't works.

uni$(rax,"rundll.dll")
invoke LoadLibraryW,uni$(rax,"rundll.dll")


and my masm64 don't know WSTR - in macros64\macros64.inc
Title: Re: How to use utf-16 strings ?
Post by: Vortex on July 03, 2021, 12:49:17 AM
Hi morgot,

You can import the required macros to your source code. Attached is a quick example.
Title: Re: How to use utf-16 strings ?
Post by: morgot on July 03, 2021, 02:13:22 AM
Thank Vortex, it's very good!
but uni$ macro don't work, only WSTR
Title: Re: How to use utf-16 strings ?
Post by: Vortex on July 03, 2021, 07:03:05 PM
Hi morgot,

Some slight modifications in the original macros ( practical solution ) :

uni$ MACRO arglist:VARARG
      LOCAL UCdata
      WSTR UCdata,arglist
      EXITM <ADDR UCdata>
    ENDM

uni2$ MACRO arglist:VARARG
      LOCAL UCdata
      WSTR UCdata,arglist
      EXITM <OFFSET UCdata>
    ENDM


include \masm32\include64\masm64rt.inc
include UnicodeMacros.asm

.data

WSTR format,"%s"

.code

start PROC

    invoke  vc_wprintf,uni$("%s"),uni$("This is a UNICODE test.",13,10)

    mov     rdx,uni2$("This is the second UNICODE test.",13,10)

    invoke  vc_wprintf,ADDR format,rdx

    invoke  ExitProcess,0

start ENDP

END


A better version of uni$ is required here to handle both of the usage cases above.