Starting a new (and improved) SimConnect ClassLibrary for .Net

Hi!

I have been experimenting with SimConnect for quite a while now, mostly in C++, first with FSX, then a lot more with Prepar3D. However, the API is kind of stuck in C era conventions. Using inheritance on structs and references instead of pointers won’t get you out of things like DWORDS, ABYSMAL_ALL_UPPERCASE constants, and Hungarian notation (for those who don’t know that term: it means you prefix identifiers with mangled types, like “lpsz” and “dw”) which was very helpful when IDEs weren’t there to tell you what an identifier is for. The extensive use of pointers and unsafe types is also a definite worry. These problems were solved and given better alternatives a long time ago, so time to move on.

C++ in itself is a nice language, but its ability to help you shoot yourself in the foot in unexpected ways means Rust would be better, if it were a bit further developed. However, if you want to write modern UIs on Windows, you’ll want to use a managed language like C# and its siblings. Now I appreciate the effort put in the Managed SimConnect library, but it kind of feels as if building it was more than enough risk for the developer and project manager involved, and no attempt appears to have been done in modernizing it.

To mention a few things I would have liked to see: proper use of classes, use of current language capabilities, and (most important) proper use of modern concurrent programming paradigms. So, if I request a value or system state, let me give a lambda (delegate if you like) to process the result. Better yet, support for System.Reactive and enumerables, so I can define a class or struct using annotations to specify the simulation variables, and get a stream pushed back to me that I can deal with where I want it. No messing with Windows messaging loops, because SimConnect gets its data in a stream from the simulator, and getting messages on my window that I need to check for fresh data is mixing things up.

So I thought this would be a nice project to start on. I’m doing this in my own time (my daytime job is in the Java world, dealing with microservices, CQRS and Event Sourcing, so next to family life, time is scarce), but everything is up on GitHub under the Apache 2.0 license. Free to use, even commercially, but under a copyright.

It is a collection of three projects:

  • CsSimConnectInterOp is a C++ DLL to expose the static SimConnect lib, adding a bit of logging so we can optionally see what is happening. If I ever manage to completely get rid of it that would be fantastic, but having a layer to sanitize and clean up the API for managed use is probably worthwhile.
  • CsSimConnect is the C# Class Library itself.
  • CsSimConnectUI is a small WPF demo program used to test.

This is very fresh, so so far it only provides for connecting to the simulator and it can subscribe to system events. The code up there now was written using the Prepar3D v4.5 SDK, but exchanging the MSFS SDK for it allowed me to connect to MSFS 2020 fine. It currently uses callback lambdas, but I’m going to add in System.Reactive next. Reactor would’ve been even better, because it provides for single results (Mono) as well as streams (Flux) out-of-the-box, but with a 0.6.something version unchanged since 2016 I’m unsure if it is a safe base. The ReactX stuff has already been moved to “System”, so (in appearance at least) seems like a safer bet.

If you want to take a look or even help, let me know. You can clone the code as it is, suggest ideas and report bugs using Issues, or make fixes and provide a PR.

Cheers,
Bert Laverman

5 Likes

Very interesting project Bert !

thank you for doing this…

I will definitely look into it, please keep it on …

kind regards
Fred