如何声明unicode字符串

_____non______ 2006-02-12 10:39:24
.data
me db "me",0

这段代码声明的是一个ASC码字符串~~

但是我现在想要声明一个unicode字符串~~

如何做?

搜索了好久都没有找到~
...全文
195 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
icbm 2006-03-25
  • 打赏
  • 举报
回复
没错,我也发现了。这个宏确实不能定义中文的字符串。

老大的办法可以试试:可以定义普通字符串,然后在代码中用 MultiByteToWideChar 转换成宽字符。

只是我有个疑问:那些开发多国语言的软件,实现Unicode的时候,究竟是怎样做的呢?我看到很多软件,有一个菜单,改变语种之后,所有的界面元素的语言都变了。哪位高人给解释一下?
PieroLsl 2006-03-25
  • 打赏
  • 举报
回复
用那个API虽然可以解决问题,但是当字符串很多时,用那个方法就实在是太夸张了~~
PieroLsl 2006-03-24
  • 打赏
  • 举报
回复
似乎用那个宏无法定义中文字符串啊 ~~
icbm 2006-02-13
  • 打赏
  • 举报
回复
szCaption  dw 7248h, 672ch, 0 ;'版本'
中文稍微麻烦点,得自己把相应的代码找出来。就象上面那个,是个UNICODE的字符串:“版本”。

目前我也没有找到直接声明中文UNICODE字符串的好办法, mydo(坎道斯|Kinds) 也是一个解决办法。

大熊猫侯佩 2006-02-13
  • 打赏
  • 举报
回复
楼上的是可以,但我觉得手动的话太麻烦了。
icbm 2006-02-13
  • 打赏
  • 举报
回复
_DATA SEGMENT
??_C@_1BA@JOHB@?$AAC?$AAa?$AAp?$AAt?$AAi?$AAo?$AAn?$AA?$AA@ DB 'C', 00H, 'a'
DB 00H, 'p', 00H, 't', 00H, 'i', 00H, 'o', 00H, 'n', 00H, 00H, 00H ; `string'
_DATA ENDS
; COMDAT ??_C@_1BA@CCGE@?$AAM?$AAe?$AAs?$AAs?$AAa?$AAg?$AAe?$AA?$AA@
_DATA SEGMENT
??_C@_1BA@CCGE@?$AAM?$AAe?$AAs?$AAs?$AAa?$AAg?$AAe?$AA?$AA@ DB 'M', 00H, 'e'
DB 00H, 's', 00H, 's', 00H, 'a', 00H, 'g', 00H, 'e', 00H, 00H, 00H ; `string'
_DATA ENDS

以上是在VC程序中定义了两个字符串,TEXT("Caption"),TEXT("Message")后,定义UNICODE宏后,由VC编译器生成的列表文件。

可以看到,UNICODE字符串每个字符是两个字节,以两个00h字符做为UNICODE字符串的结尾。




icbm 2006-02-13
  • 打赏
  • 举报
回复
上面写错了,是:
masm32 v8.2
icbm 2006-02-13
  • 打赏
  • 举报
回复
masm v8.2有一个Unicode的例子。

里边有一个转换的宏,我看不太明白,哪位大侠给解释一下。直接用就可以了。

; ------------------- UNICODE support macros for MASM32 -------------------

comment * -----------------------------------------------
macro to declare UNICODE string data in the .DATA
section.
SYNTAX:
WSTR MyString,"This is a test"
string length limit = 118 charachers
control characters like < > etc .. cannot be used
in the string.
------------------------------------------------- *
WSTR MACRO iname,text:VARARG
ustrng1 equ <>
ustrng2 equ <>
ustrng3 equ <>

addstr1 equ <>
addstr2 equ <>
addstr3 equ <>
cnt = 0

slen SIZESTR <text>

;; ------------------------------------------------
;; test for errors in length or missing quotations
;; ------------------------------------------------
if slen gt 118
echo -----------------------
echo *** STRING TOO LONG ***
echo -----------------------
.ERR
EXITM
endif

qot1 SUBSTR <text>,1,1
IFDIF qot1,<">
echo -----------------------------
echo *** MISSING LEADING QUOTE ***
echo -----------------------------
.ERR
EXITM
ENDIF

qot2 SUBSTR <text>,slen,1
IFDIF qot2,<">
echo ------------------------------
echo *** MISSING TRAILING QUOTE ***
echo ------------------------------
.ERR
EXITM
ENDIF

;; ------------------------------------------------
;; loop through the characters in the string adding
;; them in a WORD formatted form to the end of each
;; string depending on the length.
;; ------------------------------------------------
nustr SUBSTR <text>,2,slen-2
% FORC arg, <nustr>
if cnt lt 1
addstr1 CATSTR addstr1,<">,<arg>,<">
elseif cnt lt 40
addstr1 CATSTR addstr1,<,">,<arg>,<">

elseif cnt lt 41
addstr2 CATSTR addstr2,<">,<arg>,<">
elseif cnt lt 80
addstr2 CATSTR addstr2,<,">,<arg>,<">

elseif cnt lt 81
addstr3 CATSTR addstr3,<">,<arg>,<">
elseif cnt lt 120
addstr3 CATSTR addstr3,<,">,<arg>,<">
endif
cnt = cnt + 1
ENDM

;; ------------------------------------------------
;; The following three blocks append the 00 to the
;; end of the string depending on how long it is
;; ------------------------------------------------
if cnt lt 41
addstr1 CATSTR addstr1,<,00>
endif
ustrng1 CATSTR ustrng1,<iname>,< dw >,addstr1
ustrng1
if cnt lt 41
EXITM
endif

if cnt lt 81
addstr2 CATSTR addstr2,<,00>
endif
ustrng2 CATSTR ustrng2,< dw >,addstr2
ustrng2
if cnt lt 81
EXITM
endif

addstr3 CATSTR addstr3,<,00>
ustrng3 CATSTR ustrng3,< dw >,addstr3
ustrng3
ENDM
;; -------------------------------------------------

; ******************************
; FUNCTION version of the above.
; ******************************
uni$ MACRO text:VARARG

LOCAL addstr1
LOCAL iname

ustrng1 equ <>
ustrng2 equ <>
ustrng3 equ <>

addstr1 equ <>
addstr2 equ <>
addstr3 equ <>
cnt = 0

slen SIZESTR <text>

;; ------------------------------------------------
;; test for errors in length or missing quotations
;; ------------------------------------------------
if slen gt 118
echo -----------------------
echo *** STRING TOO LONG ***
echo -----------------------
.ERR
EXITM <>
endif

qot1 SUBSTR <text>,1,1
IFDIF qot1,<">
echo -----------------------------
echo *** MISSING LEADING QUOTE ***
echo -----------------------------
.ERR
EXITM <>
ENDIF

qot2 SUBSTR <text>,slen,1
IFDIF qot2,<">
echo ------------------------------
echo *** MISSING TRAILING QUOTE ***
echo ------------------------------
.ERR
EXITM <>
ENDIF

;; ------------------------------------------------
;; loop through the characters in the string adding
;; them in a WORD formatted form to the end of each
;; string depending on the length.
;; ------------------------------------------------
nustr SUBSTR <text>,2,slen-2
% FORC arg, <nustr>
if cnt lt 1
addstr1 CATSTR addstr1,<">,<arg>,<">
elseif cnt lt 40
addstr1 CATSTR addstr1,<,">,<arg>,<">

elseif cnt lt 41
addstr2 CATSTR addstr2,<">,<arg>,<">
elseif cnt lt 80
addstr2 CATSTR addstr2,<,">,<arg>,<">

elseif cnt lt 81
addstr3 CATSTR addstr3,<">,<arg>,<">
elseif cnt lt 120
addstr3 CATSTR addstr3,<,">,<arg>,<">
endif
cnt = cnt + 1
ENDM

.data
;; ------------------------------------------------
;; The following three blocks append the 00 to the
;; end of the string depending on how long it is
;; ------------------------------------------------
if cnt lt 41
addstr1 CATSTR addstr1,<,00>
endif
ustrng1 CATSTR ustrng1,<iname>,< dw >,addstr1
ustrng1
if cnt lt 41
.code
goto mclbl
endif

if cnt lt 81
addstr2 CATSTR addstr2,<,00>
endif
ustrng2 CATSTR ustrng2,< dw >,addstr2
ustrng2
if cnt lt 81
.code
goto mclbl
endif

addstr3 CATSTR addstr3,<,00>
ustrng3 CATSTR ustrng3,< dw >,addstr3
ustrng3
.code

:mclbl

EXITM <OFFSET iname>

ENDM
;; -------------------------------------------------
大熊猫侯佩 2006-02-12
  • 打赏
  • 举报
回复
可以定义普通字符串,然后在代码中用 MultiByteToWideChar 转换成宽字符。

21,459

社区成员

发帖
与我相关
我的任务
社区描述
汇编语言(Assembly Language)是任何一种用于电子计算机、微处理器、微控制器或其他可编程器件的低级语言,亦称为符号语言。
社区管理员
  • 汇编语言
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧