Author Topic: How to generate an Unicode string under MASM 6.15?  (Read 11992 times)

Iznogoode

  • Regular Member
  • *
  • Posts: 8
How to generate an Unicode string under MASM 6.15?
« on: May 03, 2017, 12:20:26 AM »
Hi,
I have some difficulty imagining how to declare a Unicode string in MASM 6.15 with a simple directive (like DUS in GoAsm, for example). I know the classic system consisting in a loop lods/stosw (with ah=0) but I won't like  having to generate code. I read a post from ragdog where he discussed about WSTR but I did not understand, even by consulting the Microsoft programming manual. Can someone give me a solution ?
Thank you in advance !

Ps: I'm afraid my English is disastrous... :greenclp:

jj2007

  • Member
  • *****
  • Posts: 10543
  • Assembler is fun ;-)
    • MasmBasic
Re: How to generate an Unicode string under MASM 6.15?
« Reply #1 on: May 03, 2017, 12:49:09 AM »
Hi Iznogoode,

There are many solutions, see e.g. Unicode and displaying non-Latin alphabets.

The lodsb+stosw trick works only for pseudo unicode, as you certainly know. This is under the hood of the Masm32 macros uc$(), uni$(), and the MasmBasic macro wChr$().

Even this works: Print "Введите текст здесь", CrLf$

What is your specific objective here? Short code, simple code, fast code, ...?

newrobert

  • Regular Member
  • *
  • Posts: 38
Re: How to generate an Unicode string under MASM 6.15?
« Reply #2 on: May 03, 2017, 04:39:47 AM »
i remember masm can call windows api mutlitto... function convert asiic to unicode string;

Iznogoode

  • Regular Member
  • *
  • Posts: 8
Re: How to generate an Unicode string under MASM 6.15?
« Reply #3 on: May 03, 2017, 06:22:12 AM »
Thank you for your responses !
@jj2007: I am a beginner in assembler under Windows after using a lot MASM under DOS in the early 90s. Being studying the structures DLGTEMPLATE and DLGITEMTEMPLATE, I discovered that the strings had to be specified in Unicode format. So I wondered about the possibility of directly declare these strings in Unicode. GoAsm (and probably NASM too) can, but not MASM 6.15 which is, if I'm not wrong, the only version to run autonomously (beyond that, Visual C ++ is required). So I do not have a specific project. Unfortunately, I don't have a PC for the moment and I will study your precious suggestions in a little more than 2 weeks.

@newrobert: thank you very much for your info. I know, indeed, the function MultiByteToWide that allows to perform this conversion but I'm rather interested in a direct declaration of the string in Unicode'

nidud

  • Member
  • *****
  • Posts: 1980
    • https://github.com/nidud/asmc
Re: How to generate an Unicode string under MASM 6.15?
« Reply #4 on: May 03, 2017, 06:33:14 AM »
It's possible to declare unicode strings directly using Asmc

Sample using DLGTEMPLATE:

https://github.com/nidud/asmc/blob/master/source/test/windows/1/test.asm

TWell

  • Member
  • ****
  • Posts: 748
Re: How to generate an Unicode string under MASM 6.15?
« Reply #5 on: May 03, 2017, 06:49:17 AM »
In old way
Code: [Select]
msg dw 'H','e','l','l','o',0

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 7539
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: How to generate an Unicode string under MASM 6.15?
« Reply #6 on: May 04, 2017, 12:14:53 AM »
There are a number of ways to do unicode in MASM which does not directly support unicode. You can put unicode strings in a resource file and load them that way. MASM32 has a tool for converting unicode text to DW sequences that you put in the initialised data section. The last way is to use the API that converts ASCII to UNICODE
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

newrobert

  • Regular Member
  • *
  • Posts: 38
Re: How to generate an Unicode string under MASM 6.15?
« Reply #7 on: May 04, 2017, 12:16:06 PM »
some editor also support unicode, such as notepad++ and ultra-edit, you can select menu from encode menu,
then you can select assic,utf-8 or usc2;

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 7539
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: How to generate an Unicode string under MASM 6.15?
« Reply #8 on: May 04, 2017, 02:57:05 PM »
The MASM32 SDK already provides a unicode editor for exactly the purpose of editing unicode RC scripts so that characters sets from around the world can be used in Windows applications created with MASM.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

jj2007

  • Member
  • *****
  • Posts: 10543
  • Assembler is fun ;-)
    • MasmBasic
FUC
« Reply #9 on: May 04, 2017, 04:57:03 PM »
some editor also support unicode

One editor also supports Formatted UniCode:

include \masm32\MasmBasic\MasmBasic.inc
  Init
  Inkey "Formatted UniCode: Введите текст здесь"
EndOfCode

> assic,utf-8 or usc2

Btw, I've heard of utf-8, but what are the others? assic, usc2?

TWell

  • Member
  • ****
  • Posts: 748
Re: How to generate an Unicode string under MASM 6.15?
« Reply #10 on: May 04, 2017, 05:16:47 PM »
What formats as source file ml.exe 6.15 accept?

jj2007

  • Member
  • *****
  • Posts: 10543
  • Assembler is fun ;-)
    • MasmBasic
Re: How to generate an Unicode string under MASM 6.15?
« Reply #11 on: May 04, 2017, 05:27:40 PM »
The snippet above builds and runs fine with ML 6.15 (and all other assemblers except ML 6.14). RichMasm exports it as UTF-8.

Even ML 10.0, AsmC and HJWasm cannot digest Unicode.

Attached three sources for testing:
- utf8
- unicode with BOM
- unicode without BOM

You can open them with RichMasm or Notepad. Qeditor opens them but the display will look a bit garbled.

W0LF

  • Regular Member
  • *
  • Posts: 6
Re: How to generate an Unicode string under MASM 6.15?
« Reply #12 on: May 05, 2017, 04:40:12 AM »
Hi all! May I ask in this tread about unicode? Thx :)
In a lot of masm's .inc-files I see macros: ifdef __UNICODE__ then bla-bla_1 else bla-bla_2.
So HOW I can define that "__UNICODE__" variable?

nidud

  • Member
  • *****
  • Posts: 1980
    • https://github.com/nidud/asmc
Re: How to generate an Unicode string under MASM 6.15?
« Reply #13 on: May 05, 2017, 05:02:32 AM »
You normally define it using a command line switch to the assembler:
ML /c /D__UNICODE__ ...

Or define it directly in (top of) the source file:
__UNICODE__ equ 1
include \masm32\include\...

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 7539
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: How to generate an Unicode string under MASM 6.15?
« Reply #14 on: May 05, 2017, 05:42:59 AM »
WOLF,

Have a read of the help files as they explain how to use the __UNICODE__ equate. When you define the equate you get the UNICODE API functions instead of the ANSI ones.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy: