flat assembler
Message board for the users of flat assembler.

Index > Windows > link the MS COFF example

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



Joined: 02 Sep 2005
Posts: 5
Richter 16 Sep 2005, 15:46
hi!

I wanne Link the MSCOFF.obj example to an real Programm.
I've used the polink.exe with this command:

"C:\fasmw164\EXAMPLES\MSCOFF\polink.exe C:\fasmw164EXAMPLES\MSCOFF\MSCOFF.OBJ"

But it says:

POLINK: error: Unresolved external symbol '__imp__MessageBoxA'.
POLINK: error: Unresolved external symbol '__mainCRTStartup'.
POLINK: fatal error: 2 unresolved external(s).

Pleas say me, what is wrong?
Thx for every kind of help!


That is the Examplecode:

Code:

; example of making Win32 COFF object file

format MS COFF

extrn '__imp__MessageBoxA@16' as MessageBox:dword

section '.text' code readable executable

 public _demo

 _demo:
        push    0
        push    _caption
        push    _message
        push    0
        call    [MessageBox]
        ret

section '.data' data readable writeable

 _caption db 'Win32 assembly',0
 _message db 'Coffee time!',0
    
Post 16 Sep 2005, 15:46
View user's profile Send private message Reply with quote
Vasilev Vjacheslav



Joined: 11 Aug 2004
Posts: 392
Vasilev Vjacheslav 16 Sep 2005, 16:00
coff.template.asm
Code:
format ms coff
public start

include '%fasminc%\win32a.inc'
include 'main.imp'

ID_DLGMAIN                      = 10

MAX_PATH                        = 260
ERROR_ALREADY_EXISTS            = 183

section '.idata' data readable writeable

  szMutex       db "template",0

section '.udata' readable writeable

  hInstance     dd ?
  hMutex        dd ?

section '.code' code readable executable

  start:
        invoke  CreateMutex,NULL,TRUE,szMutex
        mov     [hMutex],eax
        invoke  GetLastError
        cmp     al,ERROR_ALREADY_EXISTS
        jz      exit_prog

        invoke  GetModuleHandle,NULL
        or      eax,eax
        jz      exit_prog

        mov     [hInstance],eax
        invoke  DialogBoxParam,eax,ID_DLGMAIN,NULL,DialogProc,NULL

  exit_prog:
        invoke  ReleaseMutex,[hMutex]
        invoke  ExitProcess,NULL

  proc  DialogProc, hWnd,wMsg,wParam,lParam
        push    ebx esi edi
        movzx   eax,word [wMsg]
        cmp     ax,WM_COMMAND
        jz      .wmcommand
        cmp     ax,WM_CLOSE
        jz      .wmclose
        cmp     ax,WM_INITDIALOG
        jnz     .not_processed

  .wminit:
        jmp     .processed

  .wmcommand:
        ;cmp     [wParam],BN_CLICKED shl 16 + 100
        ;jnz     .processed

        jmp     .processed

  .wmclose:
        invoke  EndDialog,[hWnd],NULL

  .processed:
        xor     eax,eax
        inc     eax
        jmp     .finish

  .not_processed:
        xor     eax,eax

  .finish:
        pop     edi esi ebx
        ret
  endp

; eof
    


build.bat
Code:
@echo off

set prgname=coff.template

gorc.exe /r %prgname%.rc
scan.exe %prgname%.asm -g
golink -entry start %prgname%.obj kernel32.dll user32.dll %prgname%.res
echo _
pause
    


scan.exe is a program by Vortex, you can get it here and gorc and golink can be downloaded from www.GoDevTool.com, also you can use ms linker

_________________
[not enough memory]
Post 16 Sep 2005, 16:00
View user's profile Send private message Reply with quote
Vasilev Vjacheslav



Joined: 11 Aug 2004
Posts: 392
Vasilev Vjacheslav 16 Sep 2005, 16:05
also you can found coff examples in vortex package
Post 16 Sep 2005, 16:05
View user's profile Send private message Reply with quote
Richter



Joined: 02 Sep 2005
Posts: 5
Richter 16 Sep 2005, 16:59
Why have i to change the example?
I should be possible to link it like it is or not?
Post 16 Sep 2005, 16:59
View user's profile Send private message Reply with quote
Eoin



Joined: 16 Jun 2003
Posts: 68
Location: Ireland
Eoin 16 Sep 2005, 17:27
The example only implement a function, demo, which displays a MesssageBox. In order to make and executable you need to link it with an obj file which conatins everyting else needed for an exe. In this case the additional OBJ file(s) will at least need to contain a '__mainCRTStartup' label to be used as an entry point to the app. I think mainCRTStartup has something to do with the C runtime.

You also need to link it with the appropiate LIB file which conatins the necessary info about '__imp__MessageBoxA@16'.
Post 16 Sep 2005, 17:27
View user's profile Send private message Reply with quote
Vortex



Joined: 17 Jun 2003
Posts: 318
Vortex 17 Sep 2005, 07:22
Richter,

Here is the solution :
Code:
set fasminc=\fasmw\include
\fasm\fasm MSCoff.asm
\masm32\bin\polink /SUBSYSTEM:WINDOWS /ENTRY:demo MSCoff.obj kernel32.lib user32.lib    


You don't have to modify the source code, create a batch file containing the statements above and you will get an executable of 1536 bytes.

If you would like to get my import library package :

http://vortex.masmcode.com/files/MSCOFFlibs1.zip

Attached is the demo example with the final executable MSCoff.exe , plus the necessary import libraries kernel32.lib and user32.lib


Description:
Download
Filename: MSCoff.zip
Filesize: 39.09 KB
Downloaded: 535 Time(s)


_________________
Code it... That's all...
Post 17 Sep 2005, 07:22
View user's profile Send private message Visit poster's website Reply with quote
Richter



Joined: 02 Sep 2005
Posts: 5
Richter 17 Sep 2005, 08:17
thank you for you solution for idiots Very Happy
That is what i needed Laughing
Post 17 Sep 2005, 08:17
View user's profile Send private message Reply with quote
zolkefli



Joined: 05 Mar 2005
Posts: 12
zolkefli 10 May 2006, 15:32
where can I get polink.exe. Its free right?
Post 10 May 2006, 15:32
View user's profile Send private message Reply with quote
okasvi



Joined: 18 Aug 2005
Posts: 382
Location: Finland
okasvi 10 May 2006, 15:47
zolkefli wrote:
where can I get polink.exe. Its free right?


it comes along PellesC
http://www.smorgasbordet.com/pellesc/

_________________
When We Ride On Our Enemies
support reverse smileys |:
Post 10 May 2006, 15:47
View user's profile Send private message MSN Messenger Reply with quote
zolkefli



Joined: 05 Mar 2005
Posts: 12
zolkefli 11 May 2006, 15:26
The documentation on extrn is quite simple. I can understand this statement

extrn '__imp__MessageBoxA@16' as MessageBox:dword

What is this for '__imp__' in front of function name
What is @16 for?
and the :dword size is refer to what. The size of function return?

Thanks
Post 11 May 2006, 15:26
View user's profile Send private message Reply with quote
zubi



Joined: 27 Apr 2006
Posts: 25
Location: Turkey
zubi 11 May 2006, 16:16
What is in front and at the end of the function is the 'decoration' that compilers add to the function name. @16 is the total number of bytes that is expected by that function as parameters. In MessageBoxA case, it is 16 since it expects 4 dword sized parameters. dword at the end is the size of the data. You can use extrn to refer to any label, not necessarily a function. I think it is used for type checking.

What I can't understand is that it was supposed to be decorated as "_MessageBoxA@16". Which software is it that uses such names starting with "__imp_"?
Post 11 May 2006, 16:16
View user's profile Send private message MSN Messenger Reply with quote
zolkefli



Joined: 05 Mar 2005
Posts: 12
zolkefli 13 May 2006, 21:37
thanks zubi
The 'decoration' is still confusing me..

Another thing...
Can we create object file from DLL or LIB file?
Post 13 May 2006, 21:37
View user's profile Send private message Reply with quote
zubi



Joined: 27 Apr 2006
Posts: 25
Location: Turkey
zubi 14 May 2006, 14:53
You can 'extract' .obj files from Lib files as Libs are made of obj files anyway. A librarian should be able to add or remove object files to and from a lib. I don't know about dlls. I don't think you can extract object modules back from dlls as the symbols are already resolved, but I don't know about the issue completely.
Post 14 May 2006, 14:53
View user's profile Send private message MSN Messenger Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3175
Location: Denmark
f0dder 14 May 2006, 18:28
There's a "dll2lib" tool available, but it's commercial, clunky, and fails on a lot of DLLs.
Post 14 May 2006, 18:28
View user's profile Send private message Visit poster's website Reply with quote
Vasilev Vjacheslav



Joined: 11 Aug 2004
Posts: 392
Vasilev Vjacheslav 14 May 2006, 18:29
also dll file can be converted to lib with dll2lib program (not free) and i think from lib to object
Post 14 May 2006, 18:29
View user's profile Send private message Reply with quote
zolkefli



Joined: 05 Mar 2005
Posts: 12
zolkefli 17 May 2006, 11:03
thanks guys. I already try. You can also use polib.exe comes along PellesC to convert from DLL to LIB

zubi,
What is librarian. where can I get it.TQ again
Post 17 May 2006, 11:03
View user's profile Send private message Reply with quote
zubi



Joined: 27 Apr 2006
Posts: 25
Location: Turkey
zubi 17 May 2006, 13:31
Librarian is a software to create and manipulate libraries. Polib.exe is a librarian, you have already discovered it Smile
Post 17 May 2006, 13:31
View user's profile Send private message MSN Messenger Reply with quote
zolkefli



Joined: 05 Mar 2005
Posts: 12
zolkefli 17 May 2006, 16:35
Quote:

Librarian is a software to create and manipulate libraries. Polib.exe is a librarian, you have already discovered it


Ooooo Wink

I try several way to get .lib to .obj but cannot. don't know how actually to doit on polib.exe
Post 17 May 2006, 16:35
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 17 May 2006, 16:37
@Richter

if you already have installed gcc (like devc++), you just have to link that way :
Code:
ld -e _demo mscoff.obj libkernel32.a libuser32.a libmsvcrt.a -o mscoff.exe -s    

You just have to copy the 3 libs in the same dir of the object file.
Besides, the meaning of the @16 for messagebox@16 represent the number of parameter : here it's 4 parameters (4 * 4 bytes)
Wink

_________________
Je suis sur de 'rien', mais je ne suis pas sur du 'tout'.
Post 17 May 2006, 16:37
View user's profile Send private message Visit poster's website Reply with quote
zolkefli



Joined: 05 Mar 2005
Posts: 12
zolkefli 17 May 2006, 21:26
Actually what are the different between OBJ and LIB
Post 17 May 2006, 21:26
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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.