J
joe0301
Guest
Hello guys.
I am trying to call Fortran dll from C# Winform.
The Fortran code is very popular example which we can find in google.
I could success in C# console project but failed in C# Winform.
--- Fortran code ----------
FUNCTION TSAT11(P)
!DEC$ ATTRIBUTES ALIAS:'TSAT11' :: TSAT11
!DEC$ ATTRIBUTES DLLEXPORT :: TSAT11
!DEC$ ATTRIBUTES STDCALL :: TSAT11
!DEC$ ATTRIBUTES VALUE :: P
REAL, INTENT(IN) :: P
REAL :: TSAT11
! Examle calculation
TSAT11 = P - 273.15
RETURN
END FUNCTION
--- C# Console project (This is success) -----------
using System;
using System.Runtime.InteropServices;
namespace ConsoleApp1
{
class Program
{
[DllImport(@"D:\Temp\Dll_test1.dll")]
static extern float TSAT11(float P);
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
float p = 300f;
float t = TSAT11(p);
// returns 26.8500061
Console.WriteLine(t.ToString());
}
}
}
--- C# Winform project -------------
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//[DllImport(@"D:\Temp\Dll_test1.dll", CallingConvention = CallingConvention.StdCall)]
[DllImport(@"D:\Temp\Dll_test1.dll")]
static extern float TSAT11(float P);
private void btnDoIt_Click(object sender, EventArgs e)
{
float p = 300f;
float t = TSAT11(p); //Error still occurs here
MessageBox.Show(t.ToString());
}
}
}
Still I cannot find difference between console project and WinForm project...
Continue reading...
I am trying to call Fortran dll from C# Winform.
The Fortran code is very popular example which we can find in google.
I could success in C# console project but failed in C# Winform.
--- Fortran code ----------
FUNCTION TSAT11(P)
!DEC$ ATTRIBUTES ALIAS:'TSAT11' :: TSAT11
!DEC$ ATTRIBUTES DLLEXPORT :: TSAT11
!DEC$ ATTRIBUTES STDCALL :: TSAT11
!DEC$ ATTRIBUTES VALUE :: P
REAL, INTENT(IN) :: P
REAL :: TSAT11
! Examle calculation
TSAT11 = P - 273.15
RETURN
END FUNCTION
--- C# Console project (This is success) -----------
using System;
using System.Runtime.InteropServices;
namespace ConsoleApp1
{
class Program
{
[DllImport(@"D:\Temp\Dll_test1.dll")]
static extern float TSAT11(float P);
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
float p = 300f;
float t = TSAT11(p);
// returns 26.8500061
Console.WriteLine(t.ToString());
}
}
}
--- C# Winform project -------------
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//[DllImport(@"D:\Temp\Dll_test1.dll", CallingConvention = CallingConvention.StdCall)]
[DllImport(@"D:\Temp\Dll_test1.dll")]
static extern float TSAT11(float P);
private void btnDoIt_Click(object sender, EventArgs e)
{
float p = 300f;
float t = TSAT11(p); //Error still occurs here
MessageBox.Show(t.ToString());
}
}
}
Still I cannot find difference between console project and WinForm project...
Continue reading...