C: Get Magnetic Variation for any lat/lon

From FSDeveloper Wiki
Revision as of 10:10, 29 March 2020 by BASys (talk | contribs) (FSVersion Infobox rollout)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search



The following undocumented function may be used to avoid conflicts between navigation databases and scenery magnetic variation or for any other purpose the developer might find useful.

In your choice of your project's header files, do the following function prototype:

typedef float(__stdcall *ffe_get_magvar64)(const _llaf64*);

Then in your module_init function:

#ifdef _M_X64
#define PWORDX unsigned __int64
#else
#define PWORDX DWORD
#end

ffe_get_magvar64 fe_get_magvar64 = NULL;
void FSAPI module_init(void)
{
 HMODULE hfedll = NULL;
 GetModuleHandleEx( GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, L"fe.dll", &hfedll);
 if(hfedll )
  GetSimTime6 = (fGetSimTime)GetProcAddress(hfedll , MAKEINTRESOURCEA(4));  }

Now wherever you wish to call this function, include the header where the prototype is contained and add:

extern ffe_get_magvar64 fe_get_magvar64;

To call it and find out how much time has passed:

_llaf64 lla = {lat, lon, alt};//_llaf64 is a struct in the gauges.h. lat/lon are in degrees and alt is in meters. 
float mvar = fe_get_magvar64(&lla);

NOTE:

All FSX versions use ordinal 4. For all 32bit versions of P3D however, use the following:

fe_get_magvar64 = (ffe_get_magvar64)GetProcAddress(hfedll, "?fe_get_magvar64@@YGMQAU_llaf64@@@Z"); 

For all versions of P3D v4, use the following:

fe_get_magvar64 = (ffe_get_magvar64)GetProcAddress(hfedll, "?fe_get_magvar64@@YAMQEAU_llaf64@@@Z");