This repository has been archived by the owner on Apr 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Home
jonathan-rizk edited this page Apr 18, 2020
·
2 revisions
C is able to interoperate with many languages. This section is intended to provide a few examples of how to use the library with some popular languages.
I prefer to use static classes to organize external functions that I want to use. This class will import the function that returns the specific volume, given pressure and temperature.
ImportedFunctions.cs
using System.Runtime.InteropServices;
namespace MyProject
{
public static class ImportedFunctions
{
[DllImport(@"OWTP.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern double v_P_T(double P, double T);
}
}
You may then use the function like this
MyClass.cs
using System.Diagnostics;
namespace MyProject
{
public static class MyClass
{
public static void DoSomething(double P, double T)
{
double myDouble = ImportedFunctions(P,T);
Debug.Print($"The specific volume is {myDouble.ToString()} m^3/kg.");
}
}
}