First time here? Check out the Help page!
1 | initial version |
Thanks to @Jeremy for helping me get up and running. Here is my solution for C#:
using System;
using System.Runtime.InteropServices;
namespace ConsoleApplication21 { static class DLLMethods { [DllImport("kernel32.dll")] public static extern IntPtr LoadLibrary(string dllToLoad);
[DllImport("kernel32.dll")]
public static extern IntPtr GetProcAddress(IntPtr hModule, string procedureName);
[DllImport("kernel32.dll")]
public static extern bool FreeLibrary(IntPtr hModule);
}
class Program
{
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate long D2R_GetSingleResult([MarshalAs(UnmanagedType.LPStr)]string pszDOE2Dir,
[MarshalAs(UnmanagedType.LPStr)]string pszFileName,
int iEntryID,
float[] pfData,
int iMaxValues,
[MarshalAs(UnmanagedType.LPStr)]string pszReportKey,
[MarshalAs(UnmanagedType.LPStr)]string pszRowKey);
static void Main(string[] args)
{
// Dynamically Load Library
var pDll = DLLMethods.LoadLibrary("D2Result.dll"); // Path to D2Result.dll
// Get Address of Function
var pFunctionAddress = DLLMethods.GetProcAddress(pDll, "D2R_GetSingleResult");
// Instantiate Delegate
D2R_GetSingleResult getSingleResult = (D2R_GetSingleResult)Marshal.GetDelegateForFunctionPointer(pFunctionAddress, typeof(D2R_GetSingleResult));
string pszDOE2Dir = ; // Insert path to DOE-2 Dir i.e "C:\\DOE-2\\
string pszFileName = ; // Insert file path of where the input and run files are kept
int iEntryID = 2001001;
int iMaxValues = 1;
float[] pfData = new float[iMaxValues];
string pszReportKey = null;
string pszRowKey = null;
long result = getSingleResult(pszDOE2Dir, pszFileName, iEntryID, pfData, iMaxValues, pszReportKey, pszRowKey);
bool freedom = DLLMethods.FreeLibrary(pDll);
}
}
}