LVAR R/W using C/C++

SDK supports Prepar3D’s philosophy of an open development architecture and encourages third parties to bring new innovations with improved add-ons and training content.
Post Reply
DASnyderWI
Posts: 2
Joined: Sat Sep 25, 2021 11:43 pm

LVAR R/W using C/C++

Post by DASnyderWI »

I have some C/C++ code written to connect to SIOC (OpenCockpits) and would like to directly Read/Write LVAR data (for the CaptainSim 767 in my case) and I have not found a solution yet.

Has anyone a suggestion?

I have seen that you can use LUA scripts and FSUIPC - but that is not performant enough for some instruments (rotary input in this specific case).


I have also seen suggestions of writing a custom gauge in C/C++, but no further detail on how to actually get at the LVARS.

This is the sole issue keeping me from retiring my old FSX / Level-D 767 setup for my full-sized 767 Home Cockpit. Any guidance would be greatly appreciated!
Tadghostal
Posts: 14
Joined: Mon Jan 27, 2020 10:18 pm

Re: LVAR R/W using C/C++

Post by Tadghostal »

From my understanding, local variables are global in scope in the prepar3d and you should be able to access them the same way you would simulation variables in c++ gauges as long as they are loaded before your c++ gauge.

Basically you can look at radar alt sdk example to see how it is done. You need to get a pointer to simobject manager using QueryService(SID_SimObjectManager, IID_ISimObjectManagerV400, (void**)&spSimObjectMgr), you then can get a pointer for the baseobject (user object) using QueryInterface(IID_IBaseObjectV400, (void**)&spObject).

IBaseObjectV400 has a function "GetProperty" that has some different overloads, but you should be able to get property giving the name and units from the local variable (ie the "Some Variable" and "number" from (L:Some Variable, number)). I would use this version "GetProperty (__in LPCWSTR pszPropertyName, __in LPCWSTR pszUnitCode, __out double &dProperty, __in int index=0)" and leave the index 0.

I have never tried it with local variables but given the documentation it should work as long as the gauge where the local variable is initialized loads before your custom c++ gauge.
Tadghostal
Posts: 14
Joined: Mon Jan 27, 2020 10:18 pm

Re: LVAR R/W using C/C++

Post by Tadghostal »

Another possible work-around if the LVar is in an xml gauge, you could just register your own variables and callbacks in your c++ code and change the xml to read from your variable instead of the original one. You can access c++ registered variables like you would simulation variables in xml (ie. (A:Some Variable, number)). In this case you would want your c++ gauge to be loaded first.

This is exactly what the radar alt gauge sdk example does. You can access the variable raderaltitude in xml gauges using (A:RadarAltitude, Feet).
DASnyderWI
Posts: 2
Joined: Sat Sep 25, 2021 11:43 pm

Re: LVAR R/W using C/C++

Post by DASnyderWI »

Very much appreciate the suggestions!

I have not actually written any SimConnect code, but am an experienced developer in C/C++, so figure this is doable.

I understand from your replies that I should do this from a C++ gauge (as opposed to a stand-alone application). Did I understand that properly? What are the advantages/disadvantages of doing this as a custom gauge? The concern I have is that it would be harder to debug (Using Visual Studio Professional 2019).

Thanks again!
Tadghostal
Posts: 14
Joined: Mon Jan 27, 2020 10:18 pm

Re: LVAR R/W using C/C++

Post by Tadghostal »

The problem is you are trying to access local gauge variables and the only way to do that is through the pdk, not the simconnect interface. Simconnect can only access simulation variables.

I actually think the 2nd suggestion I gave is what you want to do, because I did not see a function to set local variables in the IBaseObject interface, only to read them.

I debug DLL's plugins all the time. What I normally do is create a solution for the prepar3d.exe, then open up the source file for the add-on dll inside that solution. You can then set break points in the source file and run the debug on prepar3d.exe. As long as the source hasn't changed since you built the dll, it will break on the break points you set. If you need to change the source file to fix some bugs, you will have to rebuild the dll and put the newly built version in the prepar3d add-ons folder or it won't break on the file anymore. You can also just attach to the prepar3d process in the debugger for your dll solution, but if you have any errors before you can attach it won't ever break point. So I find it easier to do a separate prepar3d.exe solution.

I have to add extra functionality all the time to simobjects because I work in aviation lab for a university, and we are doing a lot of things with mixed reality (have a simulator being driven by the flight state of an real aircraft flying and a test subject interacting with virtual elements while flying the real aircraft). I would not consider myself an expert in developing for prepar3d, but I do have a lot of experience. What you are trying to do sounds similar to what I have had to do, so if you have any trouble trying setup your dll, feel free to message me and I will try to help.
Post Reply