How do you use this function, wsprintf(buffer,format,)
Hi CyberGuy,
For example: convert eax (ffff) to decimal 65535 (text format to buffer)
sub esp,4*3 for adjust stack pointer (for TASM) MASM automatic adjust stack pointer with "invoke" calls
have nice days
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
Thanks, you really helped me, just one question. Do you know the format for if the number is a dword?
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:
I have an example. (my old project) All converts with wsprintf. maybe help you.
btw : sorry my bad english :)
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 :)
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.
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.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
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
Thanks
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.
The stackpointer is decremented when pushing the arguments.