Creating DLL Files with Free Basic
Posted: Sat Jun 04, 2011 4:55 pm
It's very easy to create a DLL with free basic.
You need:
http://www.freebasic.net/index.php/about
IDE FBIDE:
http://fbide.freebasic.net/
Here are a couple Free Basic Code Examples for creating a DLL.
A messagebox created with a sub-routine:
A function that adds two numbers:
Subroutines and functions are the same except the functions return a value.
Some things that tripped me up:
Alias "your_function_name" statement - prevents name mangling - do not forget this or you won't be able to call from ZGE.
The default calling convention is stdcall. If you do not use <Extern> and <end extern> - You won't be able to call it from ZGE.
Export is a necessary keyword when exporting a DLL.
To compile a DLL - you can use the IDE or use a command promt.
From the IDE:
In the Fbide menu view-settings, Click on the freebasic tab. This shows you compiler options. You will see a default Compiler command that looks like this:
Change it to this:
click the menu-->run-compile. The DLL will be found in the folder that contains your source code.
Here are the examples with zge project files - add2 example only outputs to the log window.
You need:
http://www.freebasic.net/index.php/about
IDE FBIDE:
http://fbide.freebasic.net/
Here are a couple Free Basic Code Examples for creating a DLL.
A messagebox created with a sub-routine:
Code: Select all
#include once "windows.bi"
Extern "Windows-MS"
sub msgBox Alias "msgBox"(byval msg as string, byval title as string) Export
MessageBox( null, msg, title, MB_OK )
End sub
end extern
Code: Select all
Extern "Windows-MS"
Function add2 Alias "add2"(byval x as integer,byval y as integer) As Integer export
function = x+y
End Function
end extern
Some things that tripped me up:
Alias "your_function_name" statement - prevents name mangling - do not forget this or you won't be able to call from ZGE.
The default calling convention is stdcall. If you do not use <Extern> and <end extern> - You won't be able to call it from ZGE.
Export is a necessary keyword when exporting a DLL.
To compile a DLL - you can use the IDE or use a command promt.
From the IDE:
In the Fbide menu view-settings, Click on the freebasic tab. This shows you compiler options. You will see a default Compiler command that looks like this:
Code: Select all
*<$fbc>* *<$file>*
Code: Select all
*<$fbc>* -dll *<$file>*
Here are the examples with zge project files - add2 example only outputs to the log window.