• 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 and Classes

Messages
368
Country
unitedkingdom
I may be being a bit dense as it's my first time using classes but it's time to admit the spaghetti like flow of code I have needs to be more organised.

The issue I've got is that I seem to need to open a SimConnect connection in each function in a class to get it to work, rather than opening it in the main body of code. Oddly this doesn't seem to produce any errors looking at the list of messages in the SimConnect console, even though I've made multiple SimConnect_Open calls with the same handle.

I'm still not happy with this even though it works as it doesn't seem like the right way to go about things! Is there a way of opening a SimConnect connection so it's available to all the classes in a project? Probably best to use smallish words as we appear to be at the bleeding edge of my abilities!
 
Hello,

For C# and C++/CLI (managed code) :
In your main class, create an object simconnect = new SimConnect(...)
Then you can pass it to other classes as an argument of the related methods.

Example of such a method :

internal static void RequestUserPosition(SimConnect simConnect)
{
simConnect.RequestDataOnSimObject
(SimConnectRequestId.RequestUserPosition
, SimConnectDataDefineId.FsxPosition
, SimConnect.SIMCONNECT_OBJECT_ID_USER
, SIMCONNECT_PERIOD.VISUAL_FRAME
, SIMCONNECT_DATA_REQUEST_FLAG.DEFAULT
, 0
, 0
, 0);
}

If in native C++, I guess you can do the same using the phSimConnect pointer obtain from the SimConnect_Open().


Patrick.
 
Back
Top