DLL creation
BlitzMax Forums/BlitzMax Programming/DLL creation
| ||
Ive had a search and there seems to be a few differences of opinion. Is it possible (and stable) to create a dll/s in blitzmax and if so... are there any small guides/samples? |
| ||
hmm interesting question. Could we create a .DLL that could be used in other programs? In other languages? |
| ||
Theres countless examples in the forums, and as far as i know its pretty stable. And since they are normal DLLs any application can use them. But for completeness il put it all here in one place. First heres some helper tools to help automate the process. makedef.bmx - creates def files from blitzmax sources (see the 'EXPORT appended to functions in the dll source) makelib.cmd - for easy creation of def file & compiling dll (allows spaces in the path as well as drag & drop! @echo off if not %1 == "" ( cd %~dp1 makedef %~nx1 pushd . command /c bmk makelib -r %~n1 popd ) You also need to copy dllcrt2.o from your mingw\lib dir to your blitzmax\lib dir. (thanks jsp!) And add blitzmax\bin to your PATH environment variable. And heres the actual application + dll sources app.bmx dlltest.bmx Framework BRL.Blitz SuperStrict Const COMPILE_DLL:Int = True Function ShowMessage() "Win32" 'EXPORT If COMPILE_DLL Then GCEnter() MessageBoxA 0, "Hello world from DLL!", "MessageBox", 0 EndFunction Extern "Win32" Function MessageBoxA:Int( hwnd:Int, message$z, title$z, buttons:Int) EndExtern Compiling the dll & application: makelib dlltest.bmx bmk makeapp -r app.bmx EDIT: makedef.bmx didnt handle Rem/EndRem properly & added Include handling. EDIT2: fixed batch file to handle drag & drop |
| ||
Don't forget to copy dllcrt2.o from your MinGW\lib directory into your BlitzMax\lib directory. And to have drag and drop working from any location you may like to add a cd command (blitzmax bin directory) to the makelib.cmd file. |
| ||
Oops, forgot about that one.. =) Its also good idea to add your blitzmax bin dir to your path, as you should with mingw. |
| ||
whoah.... I may have to play with this when I have time, but it sounds like I could make my little 2d engine be useable from any other language. hmm.... BIG hmm.... |
| ||
whoah.... I may have to play with this when I have time, but it sounds like I could make my little 2d engine be useable from any other language. hmm.... BIG hmm.... You're going to have a lot of issues with garbage collection if you try. |