Thanks to @Jeremy for helping me get up and running. Here is my solution for C#:
- Create a static class to access the Win32 functions needed to load an unmanaged DLL dynamically.
- Then create a delegate matching the form of the D2Result.dll function that is desired. This can then be used in a program as follows:
- pfData will store the value you are trying to retrieve.
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);
}
}
}
@pflaumingo Do you really need to load it into Visual Studio? If yes, I cannot help but I've done it in the past using Python (here - not sure if the files are up-to-date on the repo...)
Awesome, thanks for the link! I've got it up and running. I was mainly just asking for Visual Studio because C# is my preferred platform/IDE. If anyone has any insight into how to get up and running in Visual Studio (VB or C#) then that'd be awesome. I'll run with @Jeremy's work for now.
@pflaumingo just in case, I've committed my last mods. Glad you were able to get it to run!
Do you know what a -99999.0 return value means? Or more generally where I can find descriptions of the return values?
I can still only seem to get it to return -99999.0 even using your test files. I'm using 64-bit python with the 64-bit DLLs, have you seen any differences between the DLLs?