flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > if, else and defined

Author
Thread Post new topic Reply to topic
uri



Joined: 09 Apr 2004
Posts: 44
Location: L'viv, Ukraine
uri
this is pease of code (windows.asm):
Code:
format    MS COFF
macro .code { section '.text' code readable executable}

public    main as '_main'
.code
main:    call    WinMain

extrn    '__imp__MessageBoxA@16' as MessageBoxA:dword
extrn    '__imp__MessageBoxW@16' as MessageBoxW:dword

macro    STDCALL    name
{
    if    defined    UNICODE
        display    'UNCIDE'
        name    equ name#W
    else
        display    'ANSI'
        name    equ name#A
    end if
}

UNICODE    equ 2
STDCALL    MessageBox
WinMain:
    call    [MessageBox]
    xor    eax,eax
    retn
    


this is makefile:
Code:
Windows.exe: Windows.obj
    link Windows.obj /SUBSYSTEM:WINDOWS /ENTRY:main /DEFAULTLIB:\masm32\lib\kernel32.lib /DEFAULTLIB:\masm32\lib\user32.lib /DEBUG /NOLOGO

Windows.obj: Windows.asm
    fasm Windows.asm Windows.obj
    


and when i compile this program i see, what branch if defined UNICODE succesfull entered (i see UNCIDE on screen). But in debugger i see, what call [MessageBox] is call [MessageBoxA] but no [MessageBoxW]. why?

all my life i program on tasm and masm. now i want to use fasm, but i don't understand some things Sad

thanks.
Post 05 May 2004, 12:20
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
comrade



Joined: 16 Jun 2003
Posts: 1137
Location: Russian Federation
comrade
use = instead of equ for UNICODE definition

_________________
comrade (comrade64@live.com; http://comrade.ownz.com/)
Post 05 May 2004, 13:20
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
uri



Joined: 09 Apr 2004
Posts: 44
Location: L'viv, Ukraine
uri
ok, i changed
UNICODE equ 2
to UNICODE = 2

but nothing changed. I see UNCIDE but call MessageBoxA Sad
Post 05 May 2004, 13:23
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
pelaillo
Missing in inaction


Joined: 19 Jun 2003
Posts: 875
Location: Colombia
pelaillo
[edit]oops... too slow answer. Change also in name equ ... [/edit]

There is a difference between "equ" in fasm and tasm/masm. For the code you have, you need to use "=" instead.

However, let me suggest this way in order to avoid non used declarations to go in obj file:

Code:
format    MS COFF
macro .code { section '.text' code readable executable}

MB_OK   = 00h
UNICODE = 2

public    main as '_main'
if    defined    UNICODE
   extrn    '__imp__MessageBoxA@16' as MessageBox:dword
else
   extrn    '__imp__MessageBoxW@16' as MessageBox:dword
end if

.code
main:    call    WinMain

macro stdcall proc,[arg]
{
  reverse
    if  arg eq
      else
        pushd arg
    end if
  common
    call [proc]
}

WinMain:
    stdcall MessageBox,0,_title,_title,MB_OK
    xor     eax,eax
    retn

_title db 'the message',0    


There are also automated tools to prepare imports depending on linkers

http://board.flatassembler.net/topic.php?t=72
http://board.flatassembler.net/topic.php?t=1068

And info about Fasm and MS Link:
http://board.flatassembler.net/topic.php?t=479

Best Regards,
pelaillo
Post 05 May 2004, 13:27
View user's profile Send private message Yahoo Messenger Reply with quote
uri



Joined: 09 Apr 2004
Posts: 44
Location: L'viv, Ukraine
uri
pelaillo
Code:
if    defined    UNICODE
   extrn    '__imp__MessageBoxA@16' as MessageBox:dword
else
   extrn    '__imp__MessageBoxW@16' as MessageBox:dword
end if 
    


Yes, i can use this definition, but i want to have possibility to use MessageBoxW too. like this:
Code:
invoke MessageBox,1,'smt','smt',0
invoke MessageBoxW,1,'smt','smt',0
    

but i can do this with
Code:
   extrn    '__imp__MessageBoxA@16' as MessageBoxA:dword
   extrn    '__imp__MessageBoxW@16' as MessageBoxW:dword
if    defined    UNICODE
   extrn    '__imp__MessageBoxA@16' as MessageBox:dword
else
   extrn    '__imp__MessageBoxW@16' as MessageBox:dword
end if
    

but! when i want to port my masm macroses to fasm i will use constructions like
Code:
if    defined    smt
        smt1   equ smt2
    else
        smt1   equ smt3
    end if
    

many times, and this construction and do not work Sad
I do not think what it's bug, I think what i do not understand some moments. can you help me to correct build above construction (if else end if)?

sorry for my english:) do you understand me?
Post 05 May 2004, 16:04
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7108
Location: Slovakia
vid
i'm not sure if i understand what you want, but if yes then you can use
Code:
extrn    '__imp__MessageBoxA@16' as MessageBoxA:dword 
extrn    '__imp__MessageBoxW@16' as MessageBoxW:dword 
if    defined    UNICODE 
   label MessageBox dword at MessageBoxW
else 
   label MessageBox dword at MessageBoxA
end if
    

and you can also define macro like this:
Code:
macro importproc name
{
   extrn    '__imp__'#`name#'A@16' as name#A:dword 
   extrn    '__imp__'#`name#'W@16' as name#W:dword 
if    defined    UNICODE 
   label name dword at name#W
else 
   label name dword at name#A
end if
}
    

to save some typing (and loose some time at every compilation Wink)
Post 05 May 2004, 19:17
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
pelaillo
Missing in inaction


Joined: 19 Jun 2003
Posts: 875
Location: Colombia
pelaillo
Your construct is ok.
Maybe the problem is in
Code:
smt1 equ smt2    

It depends on smt2 contents. If you want to textually change smt1 in smt2 before substitutions, try with
Code:
smt1 fix smt2    

If it is simply a constant value, you should use
Code:
smt1 = smt2    

In your example:
Code:
format    MS COFF
macro .code { section '.text' code readable executable}

public    main as '_main'
.code
main:    call    WinMain

extrn    '__imp__MessageBoxA@16' as MessageBoxA:dword
extrn    '__imp__MessageBoxW@16' as MessageBoxW:dword

macro    STDCALL    name
{
    if    defined    UNICODE
        display    'UNICODE'
        name    = name#W
        display name#W
    else
        display    'ANSI'
        name    = name#A
        display name
    end if
}

UNICODE    = 2
STDCALL    MessageBox
WinMain:
    call   dword [MessageBox]
    xor    eax,eax
    retn
    
Post 05 May 2004, 19:37
View user's profile Send private message Yahoo Messenger Reply with quote
uri



Joined: 09 Apr 2004
Posts: 44
Location: L'viv, Ukraine
uri
thanks all. you are realy helpd me. see you in this forum.

thanks.
Post 06 May 2004, 05:07
View user's profile Send private message Visit poster's website ICQ Number 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-2019, Tomasz Grysztar.

Powered by rwasa.