flat assembler
Message board for the users of flat assembler.

Index > Windows > Why the return value of Api-Function doesnt work?

Author
Thread Post new topic Reply to topic
ronnie



Joined: 22 Nov 2006
Posts: 5
ronnie 22 Nov 2006, 15:38
HI this is my code:

Code:
format MS COFF


extrn '__imp__MessageBoxA@16' as MessageBox:dword
extrn '__imp__ExitProcess@4' as ExitProcess:dword


section '.text' code readable executable
public _4compiler
_4compiler:
push 0
push _S1
push _S2
push 0
call [MessageBox]

MOV   dword [v_test],eax   <--------- here is the Error !

push 0
push _S1
push [v_test]
push 0
call [MessageBox]

push 0
call [ExitProcess]
ret

section '.data' Data readable writeable
_S1       db     "Test",0
_S2       db     "Testbox !",0
    


Why the compiler says to me that there is an undefined symbol ???
Post 22 Nov 2006, 15:38
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 22 Nov 2006, 15:43
Because you didn't define it

add a "v_test dd ?" at .data section

[edit] BTW, MessageBox doesn't return a pointer to a string so I think that your second call to MessageBox will not work (unless I'm missing something)[/edit]
Post 22 Nov 2006, 15:43
View user's profile Send private message Reply with quote
ronnie



Joined: 22 Nov 2006
Posts: 5
ronnie 22 Nov 2006, 16:47
yes , thats the point now : which api-function can convert numbers to strings?
Post 22 Nov 2006, 16:47
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 22 Nov 2006, 17:46
wsprintf
Post 22 Nov 2006, 17:46
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 22 Nov 2006, 17:47
Code:
push [v_test]
push fmt
push buffer
call [wsprintf]
add esp, 12 ; Because wsprintf uses cdecl calling convention
.
.
.
fmt db "%d"
buffer rb 12
    


(The last part should go in data section)

Not tested but the point is you can use wsprintf Very Happy (or doing you own IntToStr)
Post 22 Nov 2006, 17:47
View user's profile Send private message Reply with quote
ronnie



Joined: 22 Nov 2006
Posts: 5
ronnie 22 Nov 2006, 22:07
extrn '__imp__ExitProcess@4' as ExitProcess:dword

for ExitProcess and for wsprintf ??
Post 22 Nov 2006, 22:07
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 23 Nov 2006, 02:21
I never use COFF format so I don't know, try with just '__imp__wsprintf' or '__imp__wsprintf@' or '__imp__wsprintf@8', I think that one of these should work
Post 23 Nov 2006, 02:21
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 23 Nov 2006, 03:30
just look into appropriate .lib file. It should be kernel32.lib or user32.lib, my quess
Post 23 Nov 2006, 03:30
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt 23 Nov 2006, 06:32
ronnie: you can import the crtdll.dll just like the kernel32.dll, which contain the various printf functions that you need to print integers and floats
Post 23 Nov 2006, 06:32
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.