Yeah it'll be the same result, just by thinking though the steps that the compiler would take. If it sees some code with an entry not defined in an older Orbiter, it'll fail to load the DLL. I don't know how to make a single DLL that uses a function if there, but stubs it out if not, and do that at runtime.
Code:
double getSurfaceElevation(void *href, double blon, double blat)
{
// FIXME: as the function entry point does not change, do this only once at startup
double (*my_oapiSurfaceElevation)(void *, double, double);
my_oapiSurfaceElevation = GetProcAddress(GetModuleHandle("orbiter.exe"), "oapiSurfaceElevation");
if ( my_oapiSurfaceElevation ) {
return my_oapiSurfaceElevation(href, blat, blon);
} else {
return 0;
}
Written from memory and without testing so beware of the bugs, but that's the general idea.
Use GetProcAddress to get pointer to the function at runtime and then call the function via that pointer. (The pointer type must match the function prototype.) If the function is not defined in the specified module/dll, GetProcAddress() will return NULL.
Since you are resolving the function name at runtime via GetProcAddress() then the linker never sees it and cannot complain
---------- Post added at 11:47 PM ---------- Previous post was at 11:34 PM ----------
And to check if you are running under orbiter.exe or orbiter_ng.exe:
HANDLE hOrbiter = GetModuleHandle("orbiter.exe");
if ( hOrbiter == NULL ) hOrbiter = GetModuleHandle("orbiter_ng.exe");
if ( hOrbiter == NULL ) ERROR("Dude, this is an orbiter plugin...");
...
fFunc = GetProcAddress(hOrbiter, "whateverfunctionyouneed");
---------- Post added 01-27-16 at 12:03 AM ---------- Previous post was 01-26-16 at 11:47 PM ----------
Another way of doing this, possibly cleaner:
double stub_getSurfaceElevation(void *href, double blon, double blat)
{
return 0;
}
double (*my_oapiSurfaceElevation)(void *, double, double);
// STARTUP:
my_oapiSurfaceElevation = GetProcAddress(hOrbiter, "oapiSurfaceElevation");
if ( ! my_oapiSurfaceElevation ) my_oapiSurfaceElevation = stub_oapiSurfaceElevation;
// RUNTIME:
my_oapiSurfaceElevation(....)