Reading and writing Lvar from C++

#1
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?
 
#2
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?
 
#5
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?
 

ddawson

Resource contributor
#6
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.
 
#7
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.
 
#8
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.
 
#9
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.
 

ddawson

Resource contributor
#10
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.
 
#12
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.
 

ddawson

Resource contributor
#13
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.
 

n4gix

Resource contributor
#14
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:
 
#15
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.
 
#17
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.
 
#19
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.
 
Top