Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Freebasic and dlls
#21
That feature will be on next version (already on CVS if anyone want to check it.. but you can't get the compiler to compile itself using the version 0.08b, chicken-egg problem ;), patches sent by DrV.

New command-line options are:

Code:
-dll          create a DLL, including the import library
-lib          create a static library

To create a DLL it's simple as: "fbc.exe -dll mydll.bas". mydll.bas MUST have the DllMain function inside, otherwise Windows won't load it. The import library (mydll.dll.a) is created automatically too - fbc will also not include it when building the dll, so you can have the same include file with prototypes for the DLL itself and for the apps that will use it.

New release will probably be done tomorrow, loads of bug fixes, as ever, ha.. bye........
Reply
#22
Thank you V3cz0r! Looking forward to tommorow!
Also (anyone can jump in) in the DllMain select case statement, for each reason would code need to be inserted to handle each reason or is it just a formality in construction?
Reply
#23
Full mydll example:

mydll.bi:

Code:
''
'' all FB functions are by default STDCALL on Windows and also PUBLIC,
'' so nothing else has to be added (note that FBC will not include "mydll"
'' to linker's list when creating the DLL, only when using it on an .exe)
''

declare function AddNumbers lib "mydll" alias "AddNumbers" ( byval operand1 as integer, byval operand2 as integer ) as integer


mydll.bas:

Code:
''
'' mydll -- simple dll test
''
'' compile as: fbc -dll mydll.bas (will create the mydll.dll and libmydll.dll.a files)
''
'' note: libmydll.dll.a is an import library, it's only needed when creating
''       an executable that calls any of mydll's functions, only distribute
''       the DLL files with your apps, do not include the import libraries,
''       they are useless to end-users
''

option explicit
'$include: 'win\kernel32.bi'
'$include: 'mydll.bi'

    dim shared hInstance as long
    
    ''
    '' note: do not add any executable code to the main module (ie: outside
    '' any function), because that code will never be executed as only DllMain
    '' is invoked by Windows at the initialization
    ''
    
''::::::
''
'' DllMain is the entry-point (ALWAYS needed with DLL's), don't change the prototype
''
function DllMain ( byval hModule as long, byval reason as long, byval lpReserved as long ) as integer

    select case reason
        case DLL_PROCESS_ATTACH
            hInstance = hModule
        
        case DLL_THREAD_ATTACH, DLL_THREAD_DETACH, DLL_PROCESS_DETACH
            
    end select
    
    DllMain = TRUE

end function


''::::::
''
'' simple exported function, the full prototype is at mydll.bi
''
function AddNumbers ( byval operand1 as integer, byval operand2 as integer ) as integer

    AddNumbers = operand1 + operand2

end function


test.bas:

Code:
''
'' test -- calls a mydll's function and prints the result
''
'' compile as: fbc test.bas (couldn't be simplier, eh?)
''

'$include: 'mydll.bi'

    print "1 + 2 ="; addnumbers( 1, 2 )


That only will work with the new version.
Reply
#24
Quote:That feature will be on next version (already on CVS if anyone want to check it.. but you can't get the compiler to compile itself using the version 0.08b, chicken-egg problem ;), patches sent by DrV.

I was going to try and compile the current source today as an exercise and cannot find a precompiled version of the gnu "make" utility. The main website and the other support sites all seem to say the same thing "build your version from the cvs sources". Before attempting to pull together all the pieces needed for that, does anyone have a link to a win32-ready make.exe that can be used with freebasic?
ature has its way of warning a person away from danger: The distinct black and white coloration on a skunk, the chilling buzz of a rattlesanke, a redneck handing you his beer and saying "Watch this!"
Reply
#25
If I'm not mistaken, you also need gcc, mingw or dev-cpp (c compiler) because the run time lib is coded in c.
Don't think Victor will rewrite it in fb just for the exercise...

(Althogh it would be cool to have every thing coded in fb ...)
Reply
#26
Yeah, you need Mingw32 to build the runtime library and the GNU make tool to build the compiler too, all can be downloaded at: http://www.mingw.org/download.shtml
Reply
#27
Don't think I'm ready to start messing around with the runtimes, but I would like to attempt a little "tweak" of the compiler itself.

Thanks for the link, I'm retrieving make right now.
ature has its way of warning a person away from danger: The distinct black and white coloration on a skunk, the chilling buzz of a rattlesanke, a redneck handing you his beer and saying "Watch this!"
Reply
#28
Getting an error on the LD.EXE step in the compilation process:

process_begin:
CreateProcess((null), ld.exe -T ../../bin/i386pe.x -s -subsystem console -e fb_fbc_entry --stack 2097152,2097152 obj/fbc.o obj/ast.o obj/emit.o obj/emitdbg.o obj/hash.o obj/hlp.o obj/ir.o obj/lex.o obj/parser1.o obj/parser2.o obj/parser3.o obj/parser4.o obj/parser5.o obj/parser6.o obj/parser7.o obj/parser8.o obj/reg.o obj/rtl.o obj/strpool.o obj/symb.o -o ../../fbc.exe -L ../../lib -( -lcrtdll -lfb -lkernel32 -luser32 -), ...) failed.

make (e=2): The system cannot find the file specified.
mingw32-make: *** [../../fbc.exe] Error 2

Everything appears to be sitting in the proper directory structure (tracing through all of the ../.. from the freebasic\src\compiler folder), however I am not familiar with the workings of LD.EXE and am not sure exactly what I should be looking for...
ature has its way of warning a person away from danger: The distinct black and white coloration on a skunk, the chilling buzz of a rattlesanke, a redneck handing you his beer and saying "Watch this!"
Reply
#29
Nevermind...

I had to add the path for the ld.exe (..\..\bin\ld.exe) and everything completed normally.
ature has its way of warning a person away from danger: The distinct black and white coloration on a skunk, the chilling buzz of a rattlesanke, a redneck handing you his beer and saying "Watch this!"
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)