Sign in to follow this  
Guest Koen

Question about modules in FS2002

Recommended Posts

Hi all,I'm trying to create a module (dll file) that reads out the latitude, longitude and altitude of FS2002 (without using FSUIPC.dll).I use the following code to lookup the value of the latitude:MODULE_VAR latitude = {PLANE_LATITUDE};FLOAT64 FSAPI getlatitude( PMODULE_VAR val ){ lookup_var(&latitude); return latitude.var_value.n;}When I simply print getlatitude on the screen, I get the value 0x0040100F. I'm not a C++ expert, but this looks like a memory address to me. If I'm correct, I'm wondering if there's a way to read-out the value of the address and making the value of PLANE_LATITUDE visible.All comments and suggestions are welcome... :)Kind regards,http://home.planet.nl/~duijn181/cu2/koen.jpg

Share this post


Link to post
Share on other sites
Help AVSIM continue to serve you!
Please donate today!

I'm also everything else than a C expert *lol*But try not to read the pointer direct. Example out of a Gauge manual:SINT16 nVsi = 0;MODULE_VAR curr_vsi = {VERTICAL_SPEED};lookup_var(&curr_vsi);nVsi = curr_vsi.var_value.n /////////////////////////////////////////////////////////////////////At your code:lookup_var(&latitude);latitude.var_value.n=new;return new;Regards,Harry

Share this post


Link to post
Share on other sites

Hi Harry,Thanks for the reply. :)I've changed my code to:SINT16 nLatitude = 0;...lookup_var(&latitude);nLatitude = latitude.var_value.n;return nLatitude;but whatever I try, nLatitude always returns the value I've declared in the first line. E.g. when I change my first line to SINT16 nLatitude = 500;, nLatitude will always be 500...So it looks like there's something wrong with lookup_var(&latitude);...Kind regards,http://home.planet.nl/~duijn181/cu2/koen.jpg

Share this post


Link to post
Share on other sites

read the .n value. It is a value of type double which is returned.#define LATSIF482DEG(x) ( ( ((double) (x)) / 40007000.0 * 360.0 ) )#define LONSIF482DEG2(x) ( ( ((double) (x)) / 35184372088832.0 * 45.0 ) )MODULE_VAR MMGPSLAT = {PLANE_LATITUDE}; FLOAT64 MGPSLAT;MODULE_VAR MMGPSLON = {PLANE_LONGITUDE}; FLOAT64 MGPSLON;initialize_var(&MMGPSLAT);initialize_var(&MMGPSLON);lookup_var(&MMGPSLAT);MGPSLAT = LATSIF482DEG(MMGPSLAT.var_value.n);lookup_var(&MMGPSLON);MGPSLON = LONSIF482DEG2(MMGPSLON.var_value.n);Best,

Share this post


Link to post
Share on other sites

Hi,When I try initialize_var(&MMGPSLON);, as in the post above, I get the following error: "Unhandled exception: 0xC0000005: Access Violation.". I tried several things, but I'm not sure what's the exact cause of this error... If anyone knows, please tell me. :)Kind regards,http://home.planet.nl/~duijn181/cu2/koen.jpg

Share this post


Link to post
Share on other sites

initialize_var() is not needed anymore. Just remove it from the code and everything should work fine.

Share this post


Link to post
Share on other sites

Hi,When I remove initialize_var(), I still got the memory address back instead of the value... The code I'm using now (for the latitude) is:#define LATSIF482DEG(x) ( ( ((double) (x)) / 40007000.0 * 360.0 ) )MODULE_VAR MMGPSLAT = {PLANE_LATITUDE}; FLOAT64 MGPSLAT;FLOAT64 FSAPI getlatitude(){ lookup_var(&MMGPSLAT); MGPSLAT = LATSIF482DEG(MMGPSLAT.var_value.n); return MGPSLAT;}void main(){ cout:)Kind regards,http://home.planet.nl/~duijn181/cu2/koen.jpg

Share this post


Link to post
Share on other sites

Is this code in a module (*.dll)? A dll that is in the modules subfolder of FS and is called by an external application, is loaded as a copy in the memory, so the lookup_var() in the copy loaded by FS is valid, the copy loaded by your application is not. Crashes are natural then.I tried a bit like that some time ago without much success. It is possible to link the both memories copies by using shared memory, but this still doesn't allow to share the address of lookup_var (or better the ImportTable).Arne Bartels

Share this post


Link to post
Share on other sites

No way to call lookup_var directly from a FS module. The rasons are in my previous posts. There might be some routes to circumvate this, but it needs some good programming knowledge. - One possibility would be an asynchrounous lookup where "order" a lookup from the dll copy loaded from your application, that will be "answered" by a a loop started from the dll copy loaded by FS. - Or by using the windows messaging system, the "ordering" with the use of SendMessage (synchronous) or PostMessage (asynchrounous) from the dll loaded by your app and the answering by working with a message loop that reads for the same message id. AFAIK FSUIPC uses a system like this for answering read/write orders (in a much more elaborated way).Arne Bartels

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this