08-16-2023 02:33 AM
wiebe@CARYA wrote:
Esp. those annoying physics libs (LibHuAir and Refprop) have 200 functions, each function has 1, 2 or 3 doubles as input. Having to duplicate them in a case is just silly.
I would write a little wrapper DLL. One exported function per variant of parameters.
Something like:
extern "C" __declspec(dllexport) MgErr Call1Double(char* name, double *var1);
extern "C" __declspec(dllexport) MgErr Call2Double(char* name, double *var1, double *var2);
extern "C" __declspec(dllexport) MgErr Call3Double(char* name, double *var1, double *var2, double *var3);
static HMODULE hLib = NULL;
static MgErr LoadMyLibrary(void)
{
if (!hLib)
{
hLib = LoadLibraryA(LIBRARYNAME);
if (!hLib)
return fNotFound;
}
return noErr;
}
typedef void (*Func1Double)(double *);
MgErr Call1Double(char* name, double *var1)
{
MgErr err = LoadMyLibrary();
if (!err)
{
Func1Double func = (Func1Double)GetProcAddress(hLib, name);
if (func)
func(var1);
else
return mgNotSupported;
}
return err;
}
08-16-2023 02:49 AM
@rolfk wrote:
wiebe@CARYA wrote:
Esp. those annoying physics libs (LibHuAir and Refprop) have 200 functions, each function has 1, 2 or 3 doubles as input. Having to duplicate them in a case is just silly.
I would write a little wrapper DLL. One exported function per variant of parameters.
I'd probably script it.
I have a hard time maintaining compiler toolchains. That is, once it works, I have no idea how to set it up the next time, maybe years later.
In .NET I usually make a VI that invokes .NET to compile an assembly or exe. The VI is simply committed in SCC with the rest of the code. This avoids GBs of installing VS and registration that seems to be required now, just to compile a little peace of code.
08-16-2023 03:27 AM
@rolfk wrote:
wiebe@CARYA wrote:
Esp. those annoying physics libs (LibHuAir and Refprop) have 200 functions, each function has 1, 2 or 3 doubles as input. Having to duplicate them in a case is just silly.
I would write a little wrapper DLL. One exported function per variant of parameters.
You can probably make a similar wrapper that takes a pointer and a variable number of arguments, and calls the pointer with the arguments.
If it also does the (proper) exception handling, one function could fix a lot of problems.