flat assembler
Message board for the users of flat assembler.

Index > Windows > fasm procedure called in masm

Author
Thread Post new topic Reply to topic
flapjack



Joined: 03 Dec 2010
Posts: 3
flapjack 03 Dec 2010, 09:07
hi.
i found a piece of code written in fasm.
the problem is that i need that in masm. i tried to 'translate' it but no success

so i thought of something else: to make that snippet a .lib or something, and just call it in masm.

the snippet is a program itself, so my question is this: how can i export a .lib or something from fasm to work with it in masm.

here's the snipet (program):

Code:
format PE
entry main

include 'win32a.inc'

<<variables>>

section '.code' code readable executable
  main:

<<code code code>>

proc One a, b, c, d

        <<code code code >>
        ret
endp

section '.idata' import data readable writeable
  library kernel32, 'kernel32.dll',\
          advapi32, 'advapi32.dll',\
          user32, 'user32.dll',\
          shell32, 'shell32.dll'

  include 'api\kernel32.inc'
  include 'api\advapi32.inc'
  include 'api\user32.inc'
  include 'api\shell32.inc'       

    



so i want to export this program into a procedure and just call it from my masm program like for example:

invoke procedure_from_fasm

thanks in advance
Post 03 Dec 2010, 09:07
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3499
Location: Bulgaria
JohnFound 03 Dec 2010, 10:21
You better separate only the needed procedure and compile it to COFF. Then you can link the object file with your program.
Read more here: http://flatassembler.net/docs.php?article=manual#2.4.3
Post 03 Dec 2010, 10:21
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
flapjack



Joined: 03 Dec 2010
Posts: 3
flapjack 03 Dec 2010, 14:41
thanks john, but i don't know how to do that

also, when i said i want to call a procedure, i was refering to the whole snippet

so the question was supposed to be:

how to compile that snippet into a library or something that i will use in masm to call that snippet with something like :

invoke fasm_snippet


i really appreciate your help, but maybe some compiling instructions (step by step) would make my day.

thanks
Post 03 Dec 2010, 14:41
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3499
Location: Bulgaria
JohnFound 03 Dec 2010, 15:03
The above snipped will be compiled to .exe file. That the directive "format PE" means.
You simply can't use it in this form, except you need windows PE file.
That's why, you should change "format PE" to something more suitable for invoke from external code. Here you can two options - "format PE DLL" in order to create DLL and "format COFF" ("format MS COFF") in order to compile it to object file, that later can be linked with your application.
It is highly recommended to read FASM manual and especially the section about format directive.
The rest is very easy - load the edited code in FASMW and start "Compile" from the menu. Then get the created object (or DLL) file and use it with MASM linker to build the application.
Post 03 Dec 2010, 15:03
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 03 Dec 2010, 15:21
flapjack,

Are you familiar with compile/link? Here's example:
Code:
; SaySomething.fasm
        format  MS COFF
        include "Win32A.Inc"
        section ".text" executable readable code
        proc    SaySomething stdcall something: dword
        invoke  MessageBox, HWND_DESKTOP, [something], NULL, MB_OK
        ret
        endp
        public  SaySomething as "_SaySomething@4"; stdcall decoration
        extrn   "__imp__MessageBoxA@16" as MessageBox: dword; dllimport stdcall decoration    
Code:
; GottaSaySomething.masm
     .386
        .model  flat, stdcall
       externdef SaySomething: proto stdcall something: dword
      .data
something db   "Hello, world!", 0

    .code
here:      invoke  SaySomething, ADDR something
        ret

     end     here    
Post 03 Dec 2010, 15:21
View user's profile Send private message Reply with quote
flapjack



Joined: 03 Dec 2010
Posts: 3
flapjack 05 Dec 2010, 18:24
baldr wrote:
flapjack,

Are you familiar with compile/link? Here's example:
Code:
; SaySomething.fasm
        format  MS COFF
        include "Win32A.Inc"
        section ".text" executable readable code
        proc    SaySomething stdcall something: dword
        invoke  MessageBox, HWND_DESKTOP, [something], NULL, MB_OK
        ret
        endp
        public  SaySomething as "_SaySomething@4"; stdcall decoration
        extrn   "__imp__MessageBoxA@16" as MessageBox: dword; dllimport stdcall decoration    
Code:
; GottaSaySomething.masm
   .386
        .model  flat, stdcall
       externdef SaySomething: proto stdcall something: dword
      .data
something db   "Hello, world!", 0

    .code
here:      invoke  SaySomething, ADDR something
        ret

     end     here    


i compiled the fasm code, i got one.obj
i compiled the masm code, i got two.obj

then when i tried to link them into an .exe, i got an error: unresolved external symbol __imp__messageboxa@16

i tried to make the exe in masm linker with the following line:
\masm32\bin\link.exe /SUBSYSTEM:WINDOWS /OUT:three.exe one.obj two.obj

now i know i may have a linker problem. any suggestions?
Post 05 Dec 2010, 18:24
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 05 Dec 2010, 18:59
flapjack,

MessageBox() is somewhat external to both source files, did you use user32.lib in link's command line? There is at least one method to tell linker about it in the source, you may apply any of them.
Post 05 Dec 2010, 18:59
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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.