Author Topic: how to import dll correctly  (Read 19055 times)

nobody

  • Guest
how to import dll correctly
« on: October 05, 2007, 08:20:15 PM »
hi,
i'm new to nasm and experiencing problems trying to write a winapi "hello world".
the idea is simple: use messagebox to display the text. unfortunately i'm getting
the error "parser: instruction expected" on the "IMPORT".

my code:

[BITS 32]

[SEGMENT .code]

EXTERN MessageBoxA
IMPORT MessageBoxA user32.dll

mov eax, 0
ret

i'm typing nasm 1.asm -f coff to build object file.
what's wrong?
thanks in advance.

felix =)

nobody

  • Guest
Re: how to import dll correctly
« Reply #1 on: October 06, 2007, 01:00:46 AM »
The import directive only works with the omf object format.

Try:
nasm 1.asm -f obj

----
nmt

nobody

  • Guest
Re: how to import dll correctly
« Reply #2 on: October 06, 2007, 11:07:41 AM »
Thanks. Now it works, but now I can't build the exe with gcc?
ld seems not to recognize that omf format at all. how do i
build that obj file to exe? (i'm using cygwin) ?

felix =)

nobody

  • Guest
Re: how to import dll correctly
« Reply #3 on: October 06, 2007, 05:02:22 PM »
I do it in this way (mingw, cygwin)...

1. Source code:

bits 32

extern _MessageBoxA@16
global entry

section .code

entry:

push byte 0
   push msg
   push caption
   push byte 0
   call dword _MessageBoxA@16

ret

msg   db "hell", 0
caption   db "message", 0

; ------

2. Makefile:

NAME=1

$(NAME).exe:$(NAME).obj
   ld $(NAME).obj -o $(NAME).exe -e entry --subsystem windows -luser32

$(NAME).obj:$(NAME).asm
   nasm $(NAME).asm -fwin32


run:$(NAME).exe
   ./$(NAME).exe

clean:
   rm *.exe *.obj

; -----

3. Command line from msys or cygwin:
make run

; -----

You can write some macro to do it easy. We can help you.

-----
nmt