News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

passing a variable to uni$

Started by clip32, November 05, 2009, 04:33:47 AM

Previous topic - Next topic

clip32

Hi, how can I pass a variable to uni$?

for example I would like to do something like:

strBuffer db "Passme",0

str$(addr Passme)

instead of:

str$("Passme")


Thank you

jj2007

Quote from: clip32 on November 05, 2009, 04:33:47 AM
Hi, how can I pass a variable to uni$?
str$(addr Passme)

Your question is pretty unclear. What do you mean with uni$: Unicode-string?? str$("passme") doesn't make sense, in contrast to str$(123)...

This makes sense:

myval dd 123
...
str$(myval)

But that is not what you want, it seems. Hint: Try MasmBasic, it even has a wChr$("Test"), in case you really need Unicode.

hutch--

Cluip,

the "str$()" macro is a conversion from a number to a text string. You pass an actual string by its ADDRESS. If its in the .DATA section use OFFSET, if its from dynamic code use the pointer that is returned from various functions.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

MichaelW

clip32,

The uni$ macro defines a Unicode string in the data section, at assembly time. If you need to convert an existing character string to a Unicode string, it will need to be done at run time. One possibility would be to use the MultiByteToWideChar function.

eschew obfuscation

clip32

oh silly me, i mean't uni$ not str$.

thank you for the answers, the MultiByteToWideChar function did it.


regards everyone,



jj2007

Quote from: clip32 on November 06, 2009, 04:14:10 AM
thank you for the answers, the MultiByteToWideChar function did it.

wChr$() uses a simpler lodsb, stosw algo, but it also does the job.

Quoteinvoke MessageBoxW, 0, wChr$("Hello Masm32"), wChr$("Unicode is simple:"), MB_OK

               Open "O", #1, "Wide.txt"
               wPrint #1, wChr$("This is Unicode", 13, 10)
               Close