Compiling a .dll from bmx code?

BlitzMax Forums/BlitzMax Programming/Compiling a .dll from bmx code?

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

You can

here's an example:
1. create any folder where you'll create your dll in.
the file names I'll tell you refer to this folder.
2. create a file "DLLTest.bmx"
3. this should be the file content:
Strict
Framework brl.blitz

Function Product ( A , B )
  Return A * B
EndFunction
4. create a file "DLLTest.def"
5. here's the file's content:
EXPORTS
Product=bb_Product
6. open a command prompt
7. if you haven't added the "bin" directory of your BlitzMax installation to the "Path" environment variable, you need to change the current directory to this directory using the CD command.
8. call
bmk.exe makelib <i>bmx-file-path</i>
for debug or
bmk.exe makelib -r <i>bmx-file-path</i>
for release version
("bmx-file-path" needs to be a path to the "DLLTest.bmx" file)
9. the dll is now created, it's named "DLLTest.dll" - to test whether the dll is working do the following:
10. create a file "DLLCaller.bmx"
11. the file's contents are:
Strict
Framework brl.blitz

Import pub.win32

Local Library = LoadLibraryA ( "DLLTest.dll" )
If Not Library
  WriteStdout "Library not found!~n"
  Return
EndIf
Local Product ( A , B ) = GetProcAddress ( Library , "Product" )
If Not Product
  WriteStdout "Product function not found!~n"
  Return
EndIf
WriteStdout "The product of 3 and 5 is " + Product ( 3 , 5 ) + ".~n"
FreeLibrary Library

Extern "Win32"
  Function FreeLibrary ( Library )
EndExtern
12. build and run the file, if the output is
The product of 3 and 5 is 15.
you've successfully built and tested a dll using BlitzMax