How do you use this function, wsprintf(buffer,format,)
Posted on 2002-09-21 16:54:05 by CyberGuy
Hi CyberGuy,





int wsprintf(

LPTSTR lpOut, // address of buffer for output
LPCTSTR lpFmt // address of format-control string
... // optional arguments
);




For example: convert eax (ffff) to decimal 65535 (text format to buffer)




.
.data

capt db 'Deneme',0
format db '%08ld',0 ; for 000065535 if you want 65535 use '%ld',0
buffer db 20 dup (0)

.code

main:
mov eax,0ffffh ; 65535

call _wsprintfA, offset buffer, offset format, eax
sub esp,4*3
call MessageBoxA, 0 ,offset buffer, offset capt, 0
call ExitProcess , 0



sub esp,4*3 for adjust stack pointer (for TASM) MASM automatic adjust stack pointer with "invoke" calls


have nice days
Posted on 2002-09-21 19:31:33 by CYDONIA
Thanks, you really helped me, just one question. Do you know the format for if the number is a dword?
Posted on 2002-09-22 12:07:58 by CyberGuy
Hi CyberGuy,

All formats are dword (32bit). wsprintf C based API and format parameter is like a key. If you can convert dword to decimal text format is '%d',0 or convert for hex to string hex (eax=1a2b3c4d--> '%lx' --> '1A2B3C4D')


You can one or more register for convert. For example:



.data

format '%ld',0
result db 'eax = %ld and ebx = %ld',0
...

.code
....
call _wsprintfA, offset buffer, offset format, eax,ebx



I have an example. (my old project) All converts with wsprintf. maybe help you.

btw : sorry my bad english :)
Posted on 2002-09-22 17:43:04 by CYDONIA
That doesn't seem to work in FASM, it works fine if you use any dd variables, but with dw variables it doesn't work right. Try it in FASM and tell me if I'm doing something wrong.
Posted on 2002-09-23 15:41:12 by CyberGuy
xor eax, eax

movsx eax, [ThisVariableIsWORDInSize] ;sign extend

or

xor eax, eax
movzx eax, [ThisVariableIsWORDInSize] ;zero extend
EAX now contains the value of the WORD size variable.
Posted on 2002-09-23 16:34:20 by stryker
Windows works in 32bit, which means that each and every API call needs a dd (DWORD) to get passed to. dw's (WORDS) just don't do it and you have to use strykers solution on making it a dword size.

Another way on preserving the stack before/after wsprintf is to (lazy way out):

mov ebp,esp
call wsprintf, etc, etc, etc...
mov esp,ebp
Posted on 2002-09-23 17:04:47 by JimmyClif
Thanks
Posted on 2002-09-27 14:13:58 by CyberGuy
Cydonia, in your code-example, shouldn't the adjustment of the stack pointer be an addition instead of a subtraction. :)
The stackpointer is decremented when pushing the arguments.
Posted on 2002-09-27 19:48:08 by david