im getting strange results. here is my code:


.model flat, stdcall
option casemap:none
include \masm32\include\
include \masm32\include\
include \masm32\include\
includelib user32.lib
includelib kernel32.lib

testing db "200",0
fmt db "%hu",0

buffer dd ?

invoke wsprintf,addr buffer,addr fmt,addr testing
invoke MessageBox,0,addr buffer,0,0
invoke ExitProcess,NULL
end start
Posted on 2002-01-29 02:03:52 by smurf
Hi smurf...

"testing" ("200") is a string, not a number... and the %hu format waits for a plain number and not an ascii one...
Posted on 2002-01-29 02:07:46 by JCP
your buffer is only one dword not enought for the string. Maybe something like this

buffer db 50 dup(?) ;creates an uninitialised buffer 50 bytes long
Posted on 2002-01-29 02:08:53 by Quantum
readiosys: how would i make the conversion then? is wsprintf capable of doing it?

Quantum: ill make more room just in case
Posted on 2002-01-29 02:13:06 by smurf
the masm32 library provides functions to convert an ascii number to a plain number while wsprintf can only do integer to ascii conversions complying to a specified format.
Posted on 2002-01-29 02:25:41 by JCP
You can use "atodw" function from masm32 library

include \masm32\include\
includelib \masm32\lib\masm32.lib

(You will need to ensure the string in buffer is null terminated)

testing db "200",0

invoke atodw, addr testing <- return in eax "200"
Posted on 2002-01-29 05:10:53 by elmenda
thnaks everyone. i tried using the masm32 lib before but i forgot i still needed to convert it again with wsprintf to display it in a message box.
Posted on 2002-01-29 09:40:40 by smurf