Hi guys,
I'm trying to save some numbers (0-512) to my .txt file so that they make label for each line.
Something like
1 :
....
512 :
Problem is that when I add :
invoke wsprintfA, offset bufor, "%d", offset nr_znaku
my program stops at wsprintfA.
.....
wsprintfA PROTO C :VARARG
.....
_DATA SEGMENT
bufor DB 128 dup(?)
nr_znaku DD 0
......
nr_znaku increases properly - when I don't use wsprintfA my program writes to the .txt file ASCII signs that represent each value (I'm using WriteFile) ..
I've been looking for a solution for a few hours but nothing seems to work.
Please help me..
Best regards,
Daniel :-)
Quote.386
.model flat, stdcall
option casemap :none
include \MASM32\INCLUDE\windows.inc
include \MASM32\INCLUDE\user32.inc
include \MASM32\INCLUDE\kernel32.inc
includelib \MASM32\LIB\user32.lib
includelib \MASM32\LIB\kernel32.lib
.data
mestitle db "Bomz",0
form db "EAX: %u", 0
.data?
buffer db 512 dup(?)
.code
start:
mov eax, 123456
invoke wsprintf,ADDR buffer,ADDR form,eax
invoke MessageBox,0,ADDR buffer,ADDR mestitle,MB_ICONASTERISK
invoke ExitProcess,0
end start
Quote from: daniek91 on January 21, 2012, 08:28:17 PMinvoke wsprintfA, offset bufor, "%d", offset nr_znaku
INVOKE doesn't support literal strings as argument ("%d"). Instead of a string pointer, the ASCII codes of '%' and 'd' are pushed. Move the string to the data section or use the fn-macro, which allows the use of string literals.
Hi daniek91,
Here is a quick example for you :
include wsprintfTest.inc
BUFSIZE equ 128
.data
FileName db 'test.txt',0
_format db '%d :',13,10,0
.data?
buffer db BUFSIZE dup(?)
.code
start:
call main
invoke ExitProcess,0
main PROC uses esi edi ebx
LOCAL bWritten:DWORD
invoke CreateFile,ADDR FileName,GENERIC_WRITE,\
0,0,CREATE_ALWAYS,0,0
mov edi,eax
mov ebx,512
xor esi,esi
@@:
inc esi
invoke wsprintf,ADDR buffer,ADDR _format,esi
lea ecx,bWritten
invoke WriteFile,edi,ADDR buffer,eax,ecx,0
dec ebx
jnz @b
invoke CloseHandle,edi
ret
main ENDP
END start
Quote from: qWord on January 21, 2012, 08:43:48 PM
Quote from: daniek91 on January 21, 2012, 08:28:17 PMinvoke wsprintfA, offset bufor, "%d", offset nr_znaku
INVOKE doesn't support literal strings as argument ("%d"). Instead of a string pointer, the ASCII codes of '%' and 'd' are pushed. Move the string to the data section or use the fn-macro, which allows the use of string literals.
Ok.. so now it's :
invoke wsprintfA, offset bufor, offset format, offset nr_znaku
mov size_bufor,eax
invoke WriteFile, testFileIOOut, offset bufor,offset size_bufor, offset sth, 0
and format DB "%d"
Program works fine but it doesn't add those numbers.. Other data is written into the file correctly..
Edit : By looking at your examples everything should work just fine..
I'll try to make it work tomorrow..
Anyway THANK YOU..
Best regards,
Daniel :-)
Check the documentation:
invoke WriteFile, testFileIOOut, offset bufor,offset size_bufor, offset sth, 0
Quote from: jj2007 on January 21, 2012, 09:19:30 PM
Check the documentation:
invoke WriteFile, testFileIOOut, offset bufor,offset size_bufor, offset sth, 0
I've done that before.. No effect.. I've tried "invoke WriteFile, testFileIOOut, offset bufor,2, offset sth, 0" and other values as well :(
It only gave me longer empty space before the rest of the data..
" <something>" went into " <something>"
so I guess bufor stays empty regardless wsprintfA
giving us these little snippets of code isn't helping at all
we have no way of seeing potential errors
invoke WriteFile, testFileIOOut, offset bufor,offset size_bufor, offset sth, 0
we have to just guess what testFileIOOut, size_bufor, and sth are holding and how they are defined
if you want to test it, write it to console with the "print" macro or StdOut - they both use WriteFile
Quote from: daniek91 on January 21, 2012, 09:33:24 PM
It only gave me longer empty space before the rest of the data..
" <something>" went into " <something>"
so I guess bufor stays empty regardless wsprintfA
Again, check the documentation. wsprintf expects a ptr (an offset) to destination and format but plain variables as arguments - and %d is an integer, right? With your wrong argument. you should see the value of the offset there, a number around 401000h. Perhaps this is long enough to make wsprintf fail. Try to use invoke wsprintf, offset dest, offset format,
123
@dedndave:
invoke CreateFileA, offset testFilePathOut, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, 0, 0
mov testFileIOOut, EAX
sth DB 0
bufor DB 128 dup(?)
size_bufor DD $ - bufor
invoke wsprintfA, offset bufor, offset format,offset nr_znaku
mov size_bufor,eax
As I said before WriteFile works as it should (signs that should be put after each line numbers are on their place), but wsprintfA seems to leave the buffer (bufor) empty..
Also nr_znaku (line number) goes from 0 to 512 as it should..
@jj2007 : "invoke wsprintfA, offset bufor, offset format,123" fails as well :(
Quoteand format DB "%d"
the format string must be terminated with a zero
format db '%d',0
sth DB 0
sth should be a dword
sth dd ?
Quote from: dedndave on January 21, 2012, 10:41:43 PM
Quoteand format DB "%d"
the format string must be terminated with a zero
format db '%d',0
That one I've noticed myself..
Quote from: dedndave on January 21, 2012, 10:43:46 PM
sth DB 0
sth should be a dword
sth dd ?
But I haven't thought about that :eek
Thank You all :U
Especially dedndave :clap:
Everything works great ! :dance:
Best regards,
Daniel
thanks for the sentiment
but those other guys had the answer :U