Calling functions from a DLL developed in F#

Discussions about the BBC BASIC language, with particular reference to BB4W and BBCSDL
julle_da_costa
Posts: 2
Joined: Mon 27 Jul 2020, 22:45

Calling functions from a DLL developed in F#

Post by julle_da_costa »

Hi all,

(Background)
I am developing a program in F# aiming to simulate a mobile network with base stations, terminals (aka mobiles, both stationary and moving), landscape features impacting coverage and QoS. Common network features like cell-breathing and handover problems is also simulated.
In case you don't know F#, it is a functional language from Microsoft and is part of the .NET family.

I have had BBC Basic for Windows for quite some time (probably over 5 years) but never really did any serious stuff with it. Having migrated to BBCSDL I am now ready to use that as the graphical frontend for my simulation. (And just to nip a possible question in the bud: Why do I not use VB.NET for the UI stuff? Well, I prefer BBCSDL. Period.)

(My Problem)
I would like to call the functions I have developed in my F# program from a BBCSDL program. Compiling the F# as a DLL and then doing some simple tests with SYS "LoadLibrary" were not successful. Searching the web and this forum for the past 3 days have yielded very little apart from what is stated in the section "Introduction to the Windows API".
The actual simulation cycle would also be moved from F# to the BBCSDL program. Speed is not a key factor at this stage.

(My Question)
How can I call the F# functions from my .NET DLL in BBCSDL?

(Example F# program. Hello World, kind of...)

Code: Select all

namespace BBCSDL

module Say =
    let hello name =
        printfn "Hello %s" name
        
Kind regards,
Hakan
RichardRussell

Re: Calling functions from a DLL developed in F#

Post by RichardRussell »

julle_da_costa wrote: Mon 27 Jul 2020, 23:19 How can I call the F# functions from my .NET DLL in BBCSDL?
This is way outside my area of expertise, so I'm entirely reliant on Google to provide answers. As best as I can ascertain from that source, you cannot call a .NET DLL from a non-.NET application like BBC BASIC (and in my opinion it should therefore not be given the extension .dll because that's highly misleading). But seemingly you can persuade F# to create a 'conventional' DLL of the kind that can be called from C++, VB, etc.

If you search for "Create DLL from F#" there are a number of hits which look relevant, for example this. Any DLL which can be called from VB or C should also be callable from BBC BASIC, but if it's a C++ style (Object Oriented) DLL you may have to cope with 'mangled' function names and a different ABI.

Both BBC BASIC for Windows and BBC BASIC for SDL 2.0 have libraries for accessing the Box2D Physics Engine, which is a C++ style DLL with mangled names, so it's something that is understood and has been done before.
julle_da_costa
Posts: 2
Joined: Mon 27 Jul 2020, 22:45

Re: Calling functions from a DLL developed in F#

Post by julle_da_costa »

Hi Richard Russell,

Many thanks for the quick reply and the great link. And apologies for my late response.

I will give it a try and see how it goes.

Regards,

Hakan