I am trying to access an external DLL function from F #. I really have sweating.
Header C:
ext_def(int32) swe_calc_ut(double tjd_ut, int32 ipl, int32 iflag, double *xx, char *serr);
I imported this into F # respectively:
extern int32 ext_swe_calc_ut(double tjd_ut, int32 ipl, int32 iflag, double *xx, StringBuilder serr);
The problem is part of the array. I tried PinnedArray from F # Powerpack, but the call still failed. The char array is probably good, although I cannot verify since the call failed.
So far this is:
open System open System.Runtime.InteropServices open System.Text open Microsoft.FSharp.NativeInterop #r "FSharp.PowerPack.dll" #nowarn "51" module Sweph = [<DllImport(@"swedll32.dll", CharSet = CharSet.Ansi, EntryPoint = "swe_calc_ut")>] extern int32 ext_swe_calc_ut(double tjd_ut, int32 ipl, int32 iflag, double *xx, StringBuilder serr); /// <param name="jdnr">Julian day</param> /// <returns>Array with 6 doubles: 0:longitude, 1:latitude, 2:distance,3:speel in longitude, /// 4: speed in latitude, 5: speed in distance </returns> let ar: double array = Array.zeroCreate 6 let argx = PinnedArray.of_array ar printfn " ar: %A" ar // This fails with a "FileLoadException" printfn "ar: %A" argx // Details of FileLoadException: (*
"FSharp.Core, Version = 2.0.0.0, Culture = neutral, PublicKeyToken = b03f5f7f11d50a3a" does not match the assembly (Ausnahme von HRESULT: 0x80131040) *)
// However, if I leave the printfn for argx out, code continues and does not display this error again. let sb = new StringBuilder(50) // Vgl. Expert F
The program crashes at the moment (the console window disappears and when debugging it simply returns to the first line.
I know that I could use "use" instead of "let" with "let argx = PinnedArray.of_array ar", but the compiler will not let me get it because of the module declaration at the top.
In C #, the following implementation is implemented:
public static double[] getPlanet(int ipl, double jdnr) {
Perhaps the whole problem goes back to the FileLoad exception (although this does not appear in the dll call) - perhaps due to FSharp Powerpack?
Many thanks for your help.