How to get the C++ SimConnect API to simply return a simvar value?

Hello simmers,
I’m using the SimConnect C++ API to pull data from the sim. Sadly, there are no samples that look like what I want to accomplish. I want to create a function in C++ that would have the following signature: GetSimVar(const char* simVarKeyName, const char* unit). And I’d like this function to simply return the SimVar value. Because currently, all samples use a CALLBACK or a while loop that pulls the data continuously and treats it once they receive it, and it’s not very ideal for my project.
I hope you’ll be able to help me!
Alex.

Have you tried posting here?

You could use FSUIPC (free version) and one of the provided C++ (or C#) APIs (included with the SDK) and read the simvar value from an FSUIPC offset. Many, but not all, simvars are held in FSUIPC offsets, and it also allows you to add any available simvar to a free FSUIPC offset.

John

1 Like

Hi Alex,

This short answer is that the SimConnect API doesn’t have a method for this. You could “wrap” the API in some way to make this possible, but I don’t know of an existing such wrapper for C++. For Python there’s GitHub - odwdinc/Python-SimConnect: Python interface for MSFS2020 SimConnect.dll and for C# there is GitHub - c-true/FsConnect: Wrapper for Flight Simulator 2020 SimConnect library and perhaps others )

My WASimCommander project’s Client has such an API, but it does require using a custom WASM module on the simulator side. Don’t know if that wold suit you.

Project: GitHub - mpaperno/WASimCommander: MSFS2020 WASM Module and developer API for remote access to the Microsoft Flight Simulator 2020 "Gauge API" functions.
Example: WASimCommander/CPP_BasicConsole.cpp at main · mpaperno/WASimCommander · GitHub
Reference: WASimCommander: WASimCommander::Client::WASimClient Class Reference

Feel free to contact me with any questions.
-Max

To do this, you need reactive coding patterns, which hide the async communication with the sim. CsSimConnect is based on that approach, I’m looking at building C++ equivalents.

Hi Alex,

Is RequestData SimConnect sample not doing what you need to do? Sure, it is in a callback loop, but it gets triggered only once, on EVENT_SIM_START event, and it returns 5 simvars in a structure. Surely you can tailor it to suit your need? Or am I not understanding what you need to do?