flat assembler
Message board for the users of flat assembler.
Index
> Windows > Using wsprintf |
Author |
|
decard 04 Feb 2005, 11:56
Code: proc _testp buffer rb 10 enter lea eax,[buffer] cinvoke wsprintf,eax,'%s',"Hello" return endp |
|||
04 Feb 2005, 11:56 |
|
denial 04 Feb 2005, 12:02
Thank you... Could you maybe explain it shortly, why it's needed?
|
|||
04 Feb 2005, 12:02 |
|
Madis731 04 Feb 2005, 15:12
Code: proc _testp buffer rb 10 enter cinvoke wsprintf,[buffer],'%s',"Hello" ;Does the trick return endp |
|||
04 Feb 2005, 15:12 |
|
denial 04 Feb 2005, 15:23
But in the Win32Help it says, that cinvoke expects a pointer... and why do I need it only when I declare local?
thank you again............ |
|||
04 Feb 2005, 15:23 |
|
decard 04 Feb 2005, 15:54
In short, when you declare a global variable, its name means simply its address. But when you declare local variable, for exampe "buffer", its name actually means: "ebp+offset", and you can't push this addres directly on the stack (that's why your code didn't work). You have to load its addres with lea instruction, like in my example.
|
|||
04 Feb 2005, 15:54 |
|
denial 04 Feb 2005, 16:41
Thank you very much, you really helped me
|
|||
04 Feb 2005, 16:41 |
|
Reverend 05 Feb 2005, 11:56
denial wrote: Oh and another question: I know that I can translate integers into strings with wsprintf (via %d string). Is there also a possibility to translate floating point values into strings? In C, there was this nice "%f" format string, if I remember right. Oh yes there is Recently I wrote a small lib for FASM that has its own sprintf function. It is much more powerful than normal one. I'll just paste a piece of my lib's SDK here, and if you want to get it just go to my website: http://www.reverend.piwko.pl (don't mind it looks like MASM declaration, it's compilable under fasm) Quote: sprintf proc C ptrBuffer:DWORD, szFormat:DWORD, ptrArguments:VARARG |
|||
05 Feb 2005, 11:56 |
|
denial 07 Feb 2005, 12:31
Thank you, I'll give it a try
|
|||
07 Feb 2005, 12:31 |
|
denial 08 Feb 2005, 13:01
I've got yet another problem
At the moment I try to understand how pointers in FASM work. So I made a simple application that should display a MessageBox with a given text. But I don't pass the string to the parameters but a pointer named _ptr1, which should refer to the address of the string. However this doesn't work. The app compiles but the messagebox is empty I tried it like this: I added some Pseudo-Code comments into the code below that you can understand, what I tried to do. Code: include 'include/win32ax.inc' .code start: call _main invoke ExitProcess,0 proc _main _ptr1 dd ? enter cinvoke wsprintf,buffer,'%s',"Hello!" ;buffer="Hello" lea eax,[buffer] mov [_ptr1],dword eax ;_ptr1=&buffer; pushd 0 cinvoke wsprintf,_str1,'%s',"Caption" pushd _str1 lea eax,[_ptr1] cinvoke wsprintf,_str0,'%s',eax ;_str0=*_ptr1; pushd _str0 pushd 0 call [MsgBox] return endp .data buffer rb 20 _str0 rb 21 _str1 rb 6 section '.idata' import data readable writeable library user32,'user32.dll',\ kernel32,'kernel32.dll' import user32,\ MsgBox,'MessageBoxA',\ wsprintf,'wsprintfA' import kernel32,\ ExitProcess,'ExitProcess' If you could help me, I'd be glad. |
|||
08 Feb 2005, 13:01 |
|
Reverend 08 Feb 2005, 15:57
Quote:
This is the thing that doesn't work properly. When you write "lea" instruction it sets eax register to ADDRESS of a variable not its CONTENT. And in this case "_ptr1" is somewhere in memory (so its address doesn't interests us), but it CONTAINS the correct address. To make this example work, just change "lea" instruction to "mov", because mov gets the CONTENT of variable |
|||
08 Feb 2005, 15:57 |
|
denial 09 Feb 2005, 19:28
Oky thank you everything works fine now )
|
|||
09 Feb 2005, 19:28 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.