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

How can I convert this unmanaged C++ code to managed code in my C# app?

Messages
71
Country
norway
How can I convert this unmanaged C++ code to managed code in my C# app?

static enum DATA_DEFINE_ID { DEFINITION3 };
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION3, "Initial Position", "NULL", SIMCONNECT_DATATYPE_INITPOSITION, 0);
SIMCONNECT_DATA_INITPOSITION Init;
Init.Altitude = 5000.0;
Init.Latitude = 47.64210;
Init.Longitude = -122.13010;
Init.Pitch = -0.0;
Init.Bank = -1.0;
Init.Heading = 180.0;
Init.OnGround = 0;
Init.Airspeed = 0;

SimConnect_SetDataOnSimObject(hSimConnect, DEFINITION3, SIMCONNECT_OBJECT_ID_USER, 0, sizeof(Init), &Init);
 

DragonflightDesign

Resource contributor
Messages
936
Country
northernireland
There's no way of directly translating C++ into C# as the two languages have no relationship to each other, apart from the letter C in the name and that awful pun of C# supposed to be standing for C++++. I recognise the code snippet as coming from the P3D SDK; the information you need to be able to create the C# equivalent is in the Managed Code SDK samples but not necessarily all in one place. I'd start by looking at the fairly simple Managed Data Request and then moving on to the Managed Facility Request.
 
Messages
71
Country
norway
Thanks for your replay.

I have a large C# app using a lot of managed simconnect codes. It is working fine, but I have so far not been able to find out how to use the
SIMCONNECT_DATA_INITPOSITION structure when using simconnect.SetDataOnSimObject

It is how to use the special SIMCONNECT_DATA_INITPOSITION structure that gives me a headache

with my own Struct.Poi(s4) structure, I use the following and it works just fine

simconnect.AddToDataDefinition(DEFINITIONS.Struct_Poi, "Plane Latitude", "degrees", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);

simconnect.SetDataOnSimObject(DEFINITIONS.Struct_Poi, 0, SIMCONNECT_DATA_SET_FLAG.DEFAULT, s4);
 

DragonflightDesign

Resource contributor
Messages
936
Country
northernireland
You could approach it another way - if your Struct_Poi is placing your aircraft at the expected latitude, then build your own aircraft initialisation structure by adding the required lon/alt/airspeed/etc. to your existing test. You don't have to use the SIMCONNECT_DATA_INITPOSITION call and defining your own will also give you more flexibility over what you require.
 
Top