flat assembler
Message board for the users of flat assembler.

Index > Windows > Message Box example

Author
Thread Post new topic Reply to topic
shaolin007



Joined: 03 Sep 2004
Posts: 65
shaolin007
I guess I don't quite get it yet but I'm having trouble doing a simple MessageBox with FASM and going by Izcelion Windows MessageBox tutorial. Could someone show me an example of a MessageBox using NO-MACROS please? Thanks...
Post 24 May 2005, 19:36
View user's profile Send private message Reply with quote
Torrey



Joined: 12 Oct 2003
Posts: 78
Torrey
Here you go.
Code:
format PE GUI 4.0
entry BeginCode

include '%fasminc%\win32a.inc'

section '.code' executable readable writeable

BeginCode:
        push 0
        push txtTitle
        push txtMessage
        push 0
        call [MessageBox]

        ;or alternate way of calling api's or procs
        invoke MessageBox,0,txtMessage,txtTitle,0
        invoke ExitProcess,0
        ret

section '.data' data readable writeable

txtTitle        db      'Titlebar',0
txtMessage      db      'Hello World',0

section '.idata' import data readable writeable

  library kernel,'KERNEL32.DLL',\
          user,'USER32.DLL'

  import kernel,\
         ExitProcess,'ExitProcess'

  import user,\
         MessageBox,'MessageBoxA'     


Last edited by Torrey on 24 May 2005, 19:58; edited 1 time in total
Post 24 May 2005, 19:50
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7712
Location: Kraków, Poland
Tomasz Grysztar
Or just the PEDEMO example in the fasm for Windows package. No macros at all (actually it's the oldest program for Win32 ever written in fasm).
Post 24 May 2005, 19:53
View user's profile Send private message Visit poster's website Reply with quote
shaolin007



Joined: 03 Sep 2004
Posts: 65
shaolin007
Ok could you help me out with this part of PEDEMO and what exactly is going on? Thanks man...

Code:
section '.idata' import data readable writeable

  dd 0,0,0,RVA kernel_name,RVA kernel_table
  dd 0,0,0,RVA user_name,RVA user_table
  dd 0,0,0,0,0

  kernel_table:
    ExitProcess dd RVA _ExitProcess
    dd 0
  user_table:
    MessageBox dd RVA _MessageBoxA
    dd 0

  kernel_name db 'KERNEL32.DLL',0
  user_name db 'USER32.DLL',0

  _ExitProcess dw 0
    db 'ExitProcess',0
  _MessageBoxA dw 0
    db 'MessageBoxA',0                                    
    
Post 24 May 2005, 20:12
View user's profile Send private message Reply with quote
shaolin007



Joined: 03 Sep 2004
Posts: 65
shaolin007
I'm having trouble getting this to work in your program

Code:
include '%fasminc%\win32a.inc' 

my directory is

include 'C:\fasm\include\win32a.inc'
    


Do the '%%' mean anything special?
Post 24 May 2005, 20:14
View user's profile Send private message Reply with quote
flaith



Joined: 07 Feb 2005
Posts: 122
Location: $300:20 58 FC 60 N 300G => Vietnam
flaith
check your FASMW.INI and change lines inside it :

Quote:

[Compiler]
Memory=16384
Priority=0
[Options]
SecureSelection=0
AutoBrackets=0
AutoIndent=1
SmartTabs=1
OptimalFill=1
ConsoleCaret=1
[Colors]
Text=0,0,0
Background=255,255,255
SelectionText=255,255,255
SelectionBackground=10,36,106
Symbols=48,48,240
Numbers=0,144,0
Strings=176,0,0
Comments=128,128,128
[Font]
Face=Courier New
Height=-13
Width=0
Weight=400
Italic=0
CharSet=0
[Window]
Top=276
Left=515
Right=899
Bottom=600
Maximized=0
[Help]
Path=F:\Documents and Settings\Administrateur\Bureau\ASM\FASMHelp.chm
[Environment]
Fasminc = G:\DEV\FASM\WINDOWS\INCLUDE
Include = G:\DEV\FASM\WINDOWS\INCLUDE


last two lines

_________________
Je suis sur de 'rien', mais je ne suis pas sur du 'tout'.
Post 24 May 2005, 21:02
View user's profile Send private message Visit poster's website Reply with quote
coconut



Joined: 02 Apr 2004
Posts: 326
Location: usa
coconut
in order to eliminate the use of a hard coded path to include files, you can create an environment variable named FASMINC, and use that when pointing to your includes..

on win2000\xp right click my computer goto advanced, click the Environment Variables button at the bottom, and create a variable in the top listbox.. name it FASMINC and set the value to your include folder - no trailing backslash

by setting FASMINC to your "c:\asm\alot\of\folders\fasm\include"
you can use the %fasminc% and make it easier for yourself and to share your code among others

note: your can use the following resource section in your code, instead of manually importing every api you use, fasm will only generate import code for the api you actually use

Code:
section '.idata' import data readable writeable

  library kernel32,'KERNEL32.DLL',\
          user32,'USER32.DLL'

  include 'apia\kernel32.inc'
  include 'apia\user32.inc'
    


if you use an api from other DLLs, simply add it here
Post 24 May 2005, 21:07
View user's profile Send private message Reply with quote
shaolin007



Joined: 03 Sep 2004
Posts: 65
shaolin007
Hey thanks everyone that helped out! I finally got it to work correctly. Thanks for helping out a Windows Newbie. Smile

One last questions, why do you do this?
Code:

call [MessageBox]

instead of 

call MessageBox
    


I take its an address in the .dll?
Post 25 May 2005, 00:53
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3500
Location: Bulgaria
JohnFound
MessageBox is not a procedure label, but simply DWORD, where Windows puts actual address of MessageBox from user32.dll. This happens during loading of the PE exe file and this is the essense of so called "importing functions from dynamic linkable library (dll)).
This is the reason why imported functions should be called using indirect addressing [MessageBox].
See also the macro "invoke", intended to call imported functions.

Regards.
Post 25 May 2005, 06:58
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
Nikolay Petrov



Joined: 22 Apr 2004
Posts: 101
Location: Bulgaria
Nikolay Petrov
Wink


Description:
Download
Filename: MBFromStub.rar
Filesize: 1.33 KB
Downloaded: 168 Time(s)

Post 25 May 2005, 19:33
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-2020, Tomasz Grysztar.

Powered by rwasa.