flat assembler
Message board for the users of flat assembler.

Index > Main > How to use fasm code in visual studio c++

Author
Thread Post new topic Reply to topic
ry4n



Joined: 02 Sep 2014
Posts: 3
ry4n
Hello.asm:
include 'win32ax.inc' ; you can simply switch between win32ax, win32wx, win64ax and win64wx here

.code

start:
invoke MessageBox,HWND_DESKTOP,"Hi! I'm the example program!",invoke GetCommandLine,MB_OK
invoke ExitProcess,0

.end start

I have this hello.asm file and I want to include this file in my visual studio c++ code?
Post 02 Sep 2014, 15:41
View user's profile Send private message Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 619
cod3b453
The steps are:

- Change assembly to a COFF object file
- Change API references to external implementation links
- Set up the VC++ project to include your object file and link kernel32 and user32
- Add a dummy cpp file to allow the executable to be built
- Declare the entrypoint as public in the FASM object and set the entrypoint to start
- Explicitly define the subsystem in the VC++ project (I chose windows here) to allow correct linking

Attached is an example VS2010 project.


Description: VS2010 cpp project
Download
Filename: fasmcpp.zip
Filesize: 3.07 KB
Downloaded: 355 Time(s)

Post 02 Sep 2014, 18:22
View user's profile Send private message Reply with quote
ry4n



Joined: 02 Sep 2014
Posts: 3
ry4n
Thanks for your valuable suggestion
Post 04 Sep 2014, 10:54
View user's profile Send private message Reply with quote
ry4n



Joined: 02 Sep 2014
Posts: 3
ry4n
func_fasm.asm:

include 'win32ax.inc' ; you can simply switch between win32ax, win32wx, win64ax and win64wx here

.code
proc fun1
invoke MessageBox,HWND_DESKTOP,"Hi! I'm the example program!",invoke GetCommandLine,MB_OK
endp

how to call fun1 function from c++
Post 05 Sep 2014, 12:11
View user's profile Send private message Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 619
cod3b453
ry4n wrote:
func_fasm.asm:

include 'win32ax.inc' ; you can simply switch between win32ax, win32wx, win64ax and win64wx here

.code
proc fun1
invoke MessageBox,HWND_DESKTOP,"Hi! I'm the example program!",invoke GetCommandLine,MB_OK
endp

how to call fun1 function from c++
Similar though easier:

(-Using a normal C++ project)
- Declare the FASM function you want to reference in C++
- Change assembly to a COFF object file
- Export the function for C++ in FASM [note: you have to encode the correct link string; I normally grab this from the error string. This will change for different compilers, architectures and calling conventions]
- Add the FASM object to the link dependencies


Description: Same example calling FASM form C++
Download
Filename: fasmcpp.zip
Filesize: 3.11 KB
Downloaded: 330 Time(s)

Post 05 Sep 2014, 16:18
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-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.