Call unmanaged DLL from XOJO with Float variable type

I am trying to call an unmanaged C# DLL from Xojo with a double/float data type. I have tried several declarations of the variables but the value is never returned properly:

From C# project:
[DllExport(“SampleFunction1”, CallingConvention = CallingConvention.Cdecl)]
//Tried this:
public static Int32 SampleFunction1(float _L)
//Tried this:
public static Int32 SampleFunction1(ref float _L)

From Xojo/RB project:
//Tried this:
Declare Function SampleFunction1 Lib “MyLibrary.dll” (_L As Double) As Integer
//Tried this:
Declare Function SampleFunction1 Lib “MyLibrary.dll” (byref _L As Double) As Integer

dim L As Double
dim result As Integer = SampleFunction1(L)

The value is never passed back to Xojo/RB successfully - it’s always 0.

Solved:

Needed to use Single Xojo data type for Float C# data type.
[DllExport(“SampleFunction1”, CallingConvention = CallingConvention.Cdecl)]
public static Int32 SampleFunction1(ref float _L)

From Xojo/RB project:
Declare Function SampleFunction1 Lib “MyLibrary.dll” (byref _L As Single) As Integer

Maybe if you allocate the memory yourself and pass a Ptr to the C# function? Something like this:

Declare Function SampleFunction1 Lib "MyLibrary.dll" (_L As Ptr) As Integer Dim L As New MemoryBlock(8) dim result As Integer = SampleFunction1(L) Dim d As Double = L.DoubleValue(0)