Author Topic: How to use utf-16 strings ?  (Read 440 times)

morgot

  • Member
  • **
  • Posts: 102
How to use utf-16 strings ?
« 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.
Code: [Select]
str1 dw 's','t','r','o','k','a',0,02. use TimoVJ program to convert via
Code: [Select]
str dw 73h,74h,72h,6Fh,6Bh,61h,0
but maybe someone wrote simpler macros?
Sorry for the bad English

HSE

  • Member
  • *****
  • Posts: 1743
  • <AMD>< 7-32>
Re: How to use utf-16 strings ?
« Reply #1 on: July 02, 2021, 09:00:17 AM »
Hi morgot,

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

Use?:
Code: [Select]
uni$(rax, stroka)

morgot

  • Member
  • **
  • Posts: 102
Re: How to use utf-16 strings ?
« Reply #2 on: July 03, 2021, 12:15:57 AM »
Don't works.
Code: [Select]
uni$(rax,"rundll.dll")
invoke LoadLibraryW,uni$(rax,"rundll.dll")

and my masm64 don't know WSTR - in macros64\macros64.inc
Sorry for the bad English

Vortex

  • Member
  • *****
  • Posts: 2583
Re: How to use utf-16 strings ?
« Reply #3 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.

morgot

  • Member
  • **
  • Posts: 102
Re: How to use utf-16 strings ?
« Reply #4 on: July 03, 2021, 02:13:22 AM »
Thank Vortex, it's very good!
but uni$ macro don't work, only WSTR
Sorry for the bad English

Vortex

  • Member
  • *****
  • Posts: 2583
Re: How to use utf-16 strings ?
« Reply #5 on: July 03, 2021, 07:03:05 PM »
Hi morgot,

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

Code: [Select]
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

Code: [Select]
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.