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
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 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 :
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 !
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 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);
}
}
Thanks !
Last edited: