• Which the release of FS2020 we see an explosition of activity on the forun and of course we are very happy to see this. But having all questions about FS2020 in one forum becomes a bit messy. So therefore we would like to ask you all to use the following guidelines when posting your questions:

    • Tag FS2020 specific questions with the MSFS2020 tag.
    • Questions about making 3D assets can be posted in the 3D asset design forum. Either post them in the subforum of the modelling tool you use or in the general forum if they are general.
    • Questions about aircraft design can be posted in the Aircraft design forum
    • Questions about airport design can be posted in the FS2020 airport design forum. Once airport development tools have been updated for FS2020 you can post tool speciifc questions in the subforums of those tools as well of course.
    • Questions about terrain design can be posted in the FS2020 terrain design forum.
    • Questions about SimConnect can be posted in the SimConnect forum.

    Any other question that is not specific to an aspect of development or tool can be posted in the General chat forum.

    By following these guidelines we make sure that the forums remain easy to read for everybody and also that the right people can find your post to answer it.

Reading and writing Lvar from C++

Messages
71
Country
norway
I have a working C++ app that uses SimConnect. It is working very well.

The app can both read and write a specific airplane variables that are implemented as SimCOnnect Variables and Events.

Now I plan to add functions to both read and write Lvars from the specific airplane, as some of the airplane variables are implemented as Lvars.

I have the list of Lvars documented from the airplane developer.


But, I am lost in how to read and write to these Lvars in C++.


Could anyone give me a hint of how to do this?
 
If it's in a gauge then you can use the 'execute_calculator_code' function, if it's running as a separate executable I'm not sure if it's possible?
 
Bill,

Out of interest is there any advantage to the first method? I only chose the alternate because there was less typing involved!
 
If it's in a gauge then you can use the 'execute_calculator_code' function, if it's running as a separate executable I'm not sure if it's possible?

My C++ app is an executable. Does it mean it is not possible? Just want to make sure I understood this correctly.

I have read and write to Lvars by using FSUIPC's Lua functions some time ago. But, now I want to skip FSUIPC and make it directly from my C++ executable.

There must be a way to do this. Is binding LUA functions to C++ a way to do it?
 
You can't access LVars directly from a separate process.
You could write yourself a dll to run in process and then use a pipe, Windows socket or memory map to get the information to your app.
 
You can't access LVars directly from a separate process.
You could write yourself a dll to run in process and then use a pipe, Windows socket or memory map to get the information to your app.

As I can't implement anything in the airplane gauge, all the alternatives seems impossible. It looks like I have to continue with FSUIPC for reading/writing Lvars.
 
I would not recommend FSUIPC as that forces the user to install something they may not desire, and if you don't get a license for it... they'll have to.
 
I would not recommend FSUIPC as that forces the user to install something they may not desire, and if you don't get a license for it... they'll have to.


That was my reason for skipping FSUIPC and make an interface directly from my C++ executable.

Please correct me if I wrong, but what if I:

1. Keep my C++ executable
2. Embed a dll that acts as an interworking process between my C++ executable and the airplane gauge.


Would that be possible?

I also found the lvar_interface done by ddawson. Could that be used in some way?


AS FSUIPC manage to communicate with Lvars it sure must be a solution to my this.
 
FSUIPC runs in the FS process, that is why it can access lvars.

As you ask in the previous post, you need to create a dll that will run inside FS. It can be either a gauge, specific to one or more aircraft, or it can be a module such as FSUIPC, which loads when FS does and remains resident for the entire FS session.
Any gauge or module running inside FS can access lvars.
Once you have such a gauge or module, you can use standard Windows inter process communications procedures to access it from your external application.

You have mentioned gauges a couple of times in this thread. Do keep in mind that while lvars are declared by one or more gauges, they are global in nature and are accessible throughout all of FS's subsystems - gauges, modules, aircraft model code, etc.

That lvar interface I wrote a few years ago was defective - don't waste your time with it.
 
Your own DLL would work best, as long as it doesn't flood the sim with messages and the like.
 
Thanks for all your good feedback. It was fast and very informative for me.

I tried to use the lvar-interface with P3Dv4 ( from this link), but it didn't work. It seems to not start up, at least I didn't find it in Process Explorer. The dll.xml was correct, but..

I have learned a lot now and believe I can make my own DLL for reading Lvars and an inter-process method to my C++ executable.
 
Which version of P3D are you using? The dll you reference in the link in your previous post is, as compiled, a 32 bit dll that will not work in P3D v4.
I did include the source code, so you can recompile it as a 64 bit dll. You will still need to add the code for inter-process communications.
 
Bill,

Out of interest is there any advantage to the first method? I only chose the alternate because there was less typing involved!
None that I'm aware of. I've used both methods myself. The first because at the time I was working with another gauge programmer who's dependency on EasyGauge didn't allow him to use the simpler alternative method (at least that's what he claimed at the time).

Personally, I use only the alternative method for the same reason you do; less typing! :rotfl:
 
Which version of P3D are you using? The dll you reference in the link in your previous post is, as compiled, a 32 bit dll that will not work in P3D v4.
I did include the source code, so you can recompile it as a 64 bit dll. You will still need to add the code for inter-process communications.


As stated P3Dv4, 64bit version. I did recompiled as a 64 bit, but still I couldn't get it running. I find this strange as the code seems OK.
 
Content Error Log in Pv4 will tell you why it won't load the module.

Thanks for this hint. Error said dll not loaded found and not loaded

As I had just let VS2017 made the changes as the .sln file was from an older VS version/platform, I made a complete new dll with
the code lines from the lvar_interface and it now works.

Now it is time for making the inter-process communication coding.
 
What would be the best inter-process type, a pipe, Windows socket or memory map for using with P3Dv4. .
 
Anyone who knows how to display lvar values that I get from the

Code:
double GetLVarByName(PCSTRINGZ lvname)
{
    //checks for a valid string
    if (lvname == 0) return 0.;
    if (strlen(lvname) == 0) return 0.;
    ID i = check_named_variable(lvname);
    return get_named_variable_value(i);
}

in the lvar_interface dll to P3Dv4


I need to add this function for testing purposes during developement.
 
Back
Top