• 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.

SimConnect C# Oddities

Messages
156
Country
france
Hi all,

I'm a beginner with C#, but I made some little programs using simconnect before, in C and Java. Although I find C# very pleasant to code with, the limitations and bugs of the .NET simconnect interface are really slowing down my learning process.

Here are two workarounds I would like to share with you :

1 - The SIMCONNECT_UNUSED constant as an enum:
in MapInputEventToClientEvent you can pass the SIMCONNECT_UNUSED constant, cast to an enum to specify that you don't want to receive
"Up" events.
However SIMCONNECT_UNUSED (2^32-1 or DWORD_MAX) is too large to fit in the underlying type of enums (int by default).

To avoid overflow exceptions (apparently happening in the simconnect library), I had to specify uint or long as the basetype of my enums

Code:
enum EVENTS : uint {
    UNUSED = 0xFFFFFFFF,
}

Alternatively (EVENTS)SimConnect.SIMCONNECT_UNUSED works too


2 - eObjType field of RECV_EVENT_OBJECT_ADDREMOVE
This bug remains a mystery for me. Although declared public, in a public class and of a public type, the C# compiler doesn't let me access this field because of protection level.

I can bypass this by requesting the CATEGORY simulation variable for each created object ID, but this variable is buggy too :laughing: It is declared as an "enum" in the simulation variables document, but it always returns you the string representation of the type, even when requesting numeric value.

I find another way to access eObjType :
Code:
SIMCONNECT_RECV_EVENT_OBJECT_ADDREMOVE ev;
uint eObjType;
unsafe {
   fixed (uint *p = &ev.dwData) { 
        eObjType = *(p + 1);
    }
}
It works, but I doubt we can always assume that fields values of a class are contiguous in memory. So if some experienced C# programmer can take a look at these two problems to solve them more properly.


Thanks !
 
Last edited:
I have the same experience with both of your points. For the category i use some heuristics, actually testing the engine type of an aircraft and if it's an helo turbine it's a helicopter. A better way would be to use the "wrong" number as enum value though maybe with additional testing of the engine type since the first freeware helicopter that i downloaded had the heli's engine type set to turboprop (?!).

There are some other issues. For example i never got the crash reasons.
 
Back
Top