flat assembler
Message board for the users of flat assembler.

Index > Windows > dll call suggestion

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
karl



Joined: 07 Feb 2006
Posts: 63
Location: South Africa
karl 26 Sep 2006, 10:10
hi.

i hate having a list of dll imports at the end of my script. often i remove calls to them, so i'm importing things not needed. i know it doesn't add much to the .exe, but i'm a perfectionist.

anyway, i was hoping tomasz might think of this convention:
call[&KERNEL32.GetWindowEx]

The assembler sees the '&", assumes it's a dll, then adds KERNEL32.DLL to the import table and GetWindowEx

So you don't need to have an import table at the end. Just seems cleaner.
Post 26 Sep 2006, 10:10
View user's profile Send private message Reply with quote
karl



Joined: 07 Feb 2006
Posts: 63
Location: South Africa
karl 26 Sep 2006, 10:12
oh, and i guess this could be done with macros but again, it's not very clean...
Post 26 Sep 2006, 10:12
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20299
Location: In your JS exploiting you and your system
revolution 26 Sep 2006, 12:19
Quote:
i know it doesn't add much to the .exe, but i'm a perfectionist.
It adds nothing to the .exe. The current macros will correctly and completely eliminate all data for an unused import file.
Post 26 Sep 2006, 12:19
View user's profile Send private message Visit poster's website Reply with quote
karl



Joined: 07 Feb 2006
Posts: 63
Location: South Africa
karl 26 Sep 2006, 12:50
the import macros are really complicated. and either you have to have them in your source file, which is ugly, or you have to include it, and thus have more than one source. one source, one output is most preferable, i think.
Post 26 Sep 2006, 12:50
View user's profile Send private message Reply with quote
karl



Joined: 07 Feb 2006
Posts: 63
Location: South Africa
karl 26 Sep 2006, 12:55
oh, and with macros the imports in the source stay even if they don't end up in the .exe. so if you have a huge project you could have 20 imports written in your source that aren't ever used.
plus, everytime you want to call an import you have to check if you've imported it, and then if not write it to 2 places in your import section. why not make the assembler do this? it cleans up your code.
Post 26 Sep 2006, 12:55
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20299
Location: In your JS exploiting you and your system
revolution 26 Sep 2006, 13:03
Quote:
call[&KERNEL32.GetWindowEx]
The main problem for your suggestion is that FASM does not natively support imports of any type. The current macros do a good job of creating the import section. This also helps to encourage modular programming for larger projects and keeps everything in well defined sections of operation. FWIW I think that some of the included examples look much better with just one "include" and more emphasis on the task at hand. But that is just my opinion.
Post 26 Sep 2006, 13:03
View user's profile Send private message Visit poster's website Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1614
Location: Ukraine
shoorick 26 Sep 2006, 13:32

_________________
UNICODE forever!
Post 26 Sep 2006, 13:32
View user's profile Send private message Visit poster's website Reply with quote
karl



Joined: 07 Feb 2006
Posts: 63
Location: South Africa
karl 26 Sep 2006, 13:37
yes i agree, the macros and include system work well for modular programming, which is important for multi-developer projects. fasm tries to be a general tool and i'm only working on single-developer Windows systems. i think i might try make an assembler specific for my needs. based on fasm of course Smile, the cleanest programming system i've ever seen.
Post 26 Sep 2006, 13:37
View user's profile Send private message Reply with quote
karl



Joined: 07 Feb 2006
Posts: 63
Location: South Africa
karl 26 Sep 2006, 13:46
shoorick: interesting, thanks
Post 26 Sep 2006, 13:46
View user's profile Send private message Reply with quote
okasvi



Joined: 18 Aug 2005
Posts: 382
Location: Finland
okasvi 27 Sep 2006, 16:07
Post 27 Sep 2006, 16:07
View user's profile Send private message MSN Messenger Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 27 Sep 2006, 18:17
no problem... just learn how PE imports look and import without macros:

Code:
dd thunk1, 0, 0, name1, thunk1
dd thunk2, 0, 0, name2, thunk2
dd 0,0,0,0,0

name1 db "KERNEL32.DLL"

align 4
thunk1:
ExitProcess dd imp_ExitProcess  ;import by name
MessageBox dd imp_MessageBox  ;import by name
dd 0 ;end of imports from KERNEL32

imp_ExitProcess dw 0
db "ExitProcess"
imp_MessageBox dw 0
db "MessageMoxA"

name2 db "MyDLL.DLL"

align 4
thunk2:
dd 80000001h  ;import by ordinal #1
dd 80000100h  ;import by ordinal #0x100
dd 0 ;end of imports from MyDLL    
Post 27 Sep 2006, 18:17
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
karl



Joined: 07 Feb 2006
Posts: 63
Location: South Africa
karl 03 Oct 2006, 10:52
... thanks okasvi. i like tomasz's syntax better. but still, want no macros Smile

vid: ya, that's the method i've been using. but it sucks cause sometimes i import what i don't need. cause i build up from previous projects, end up importing lots....
Post 03 Oct 2006, 10:52
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 03 Oct 2006, 11:13
if you want to go without macros, then you must use way i described and enclose things which "if used MessageBox" etc...
Post 03 Oct 2006, 11:13
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
karl



Joined: 07 Feb 2006
Posts: 63
Location: South Africa
karl 03 Oct 2006, 13:50
hmmm ya didn't think about that. thanks
Post 03 Oct 2006, 13:50
View user's profile Send private message Reply with quote
Fungos Bauux



Joined: 19 Jan 2005
Posts: 31
Location: CWB
Fungos Bauux 03 Oct 2006, 17:10
I aways put all imports at my projects. Even if I dont use any. :O
Post 03 Oct 2006, 17:10
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1614
Location: Ukraine
shoorick 04 Oct 2006, 14:51
full imports slow down compilation sufficiently. also, full imports do not let you use ansi and unicode functions at once, if you need - Vortex' scan cover both problems.
Post 04 Oct 2006, 14:51
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8351
Location: Kraków, Poland
Tomasz Grysztar 04 Oct 2006, 18:23
shoorick wrote:
full imports do not let you use ansi and unicode functions at once, if you need

This is no longer true with latest packages.
Post 04 Oct 2006, 18:23
View user's profile Send private message Visit poster's website Reply with quote
OzzY



Joined: 19 Sep 2003
Posts: 1029
Location: Everywhere
OzzY 04 Oct 2006, 20:28
I'm using a nice way to speed-up my development cycle: compile, run, test, fix /write code, compile...

With the way I'll show here you automate the building of import section and resource section.
What you'll need:
* FASMW
* ResEd
* Win32API Documentation (Not really necessary, but helps a lot while coding)
* vbVeryBeginner's RC->FASM resource macros converter ( http://board.flatassembler.net/topic.php?t=5795)
* Vortex's Scan Utility ( http://www.vortex.masmcode.com/files/scan345.zip )
* MS-DOS command prompt

Let's begin.
1) Open up ResEd, and design a Dialog called dlgmain, a button called btnquit. Set the title and options as you like. Save as RSRC.RC.
You now have the basic look of your application.

2) Open up FASMW, and type this code:
Code:
include '%fasminc%\win32a.inc'
include '%fasminc%\macro\if.inc'

format PE GUI 4.0
entry main

section '.code' code readable executable
main:
        invoke DialogBoxParam,0,dlgmain,0,dlgproc,0
        invoke ExitProcess,0

proc dlgproc hwnd,msg,wp,lp
.if [msg]=WM_CLOSE
    invoke ExitProcess,0
.elseif [msg]=WM_COMMAND
        .if [wp]=btnquit
            invoke ExitProcess,0
        .endif
.endif
xor eax,eax
ret
endp

include 'rsrc.inc'
include 'test.imp'
    

Save as TEST.ASM.

open up MS-DOS prompt and cd to your project folder, and type:
Quote:

copy con build.bat
cscript //NoLogo rcc.vbs rsrc.rc > rsrc.inc
scan test.asm -f
fasm test.asm
[CTRL+Z]

build

You should now have test.exe! Execute it and your dialog pops-up! Very Happy
Now every time you modify rsrc.rc or test.asm just run "build" again. And your resource section and import section will always be up-to-date.

This is a very good way to keep your code modular and clean.
You can easily modify your resource file and asm file without having to worry about imports and resources messing up with your source code. And you don't even need a resource compiler or to type the imports manually.
Enjoy!!

I think this is a very confortable programming environment.
Thanks to Tomasz, vbVeryBeginner and Vortex for the amazing tools! Smile
Post 04 Oct 2006, 20:28
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 05 Oct 2006, 06:49
Tomasz: if you changed headers already, make an announcement in Windows section pls
Post 05 Oct 2006, 06:49
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
karl



Joined: 07 Feb 2006
Posts: 63
Location: South Africa
karl 05 Oct 2006, 11:07
thanks very interesting ozzy, thanks Smile
Post 05 Oct 2006, 11:07
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< 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.