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

Getting crazy with MS VC++, managed code and SimConnect

Messages
162
Country
italy
literally getting crazy, what i should have seems pretty simple but..
- Let's begin a new project with MS VC10 making a Windows application with .net in order to use already done widgets whistles and bells
- all is fine until you want try to SimConnect, no way to have it, read all is written in SDK about managed code but seems done only for C# so i am stuck ( i'd prefere do not learn C# right now)
- what i want is simple, just a dll called by a sim menu that opens a window (aircraft configurator), alternatively an application that can SimConnect to make some work.
someone out there may help me ??
i'd love a simple example, I will be eternally gratefull :-)
/Mario
 
Mario,

ok what are you getting for errors?

C# and C++ code should be similar. Maybe pointer to strings issues. Maybe post some code.

- what i want is simple, just a dll called by a sim menu that opens a window (aircraft configurator), alternatively an application that can SimConnect to make some work.

Seems a little more involved in that you want an in process menu in the sim to trigger the new window?
Not sure that can be done. Native C++ may be required.
 
Thanks Rohn for prompt answer.
Is not a compile issue, it's a link problem.
basically the linker refuses to link managed code.
I can simconnect nicely using a console application (native not managed),
the problem is that if i want use managed code in C++ i can't link.
I have found two ways:
- follow SDK indications on managed code, no success, stuck on none C++ example for that
- try to compile in native code without loose the nice gui interface builder, no success
it remains the inelegant way:
- call from FSX menu an external (managed) application that prepare a configuration file to be read by a dll
from FSX.
I would like avoid this and directly simconnect from the configuring application or better from a configuring dll.
thanks
Mario
 
I have a VS C++ example connecting to P3D - not working in FSX at the moment. Lets just say I get a valid simconnect^ object on return. Just took a C# example and modified it.

1. Ensure of the following
reference to simconnect.dll in the SDK foldr.
2. add in the two lines:

using LockheedMartin.Prepar3D.SimConnect; <- you use FSX
using System.Runtime.InteropServices;

3. use a simconnect pointer and gcnew:
SimConnect^ simulation_connection = gcnew SimConnect(safe_cast<String^>("Managed Change Vehicle"), IntPtr::Zero, 0, nullptr, 0);

I have a simple window form in C++ with a button.

Code:
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
            try
            {

                SimConnect^ simulation_connection = nullptr;
                simulation_connection = gcnew SimConnect(safe_cast<String^>("Managed Change Vehicle"), IntPtr::Zero, 0, nullptr, 0);
              
                //// Sending the title of the Vehicle
                simulation_connection->ChangeVehicle(safe_cast<String^>("Mooney Bravo Retro"));

                simulation_connection->Close();
                simulation_connection = nullptr;
            }
            catch (Exception ^ex)
            {
            //    //// We were unable to connect so let the user know why.
            //    //System.Console.WriteLine("Sim Connect unable to connect to Prepar3D!\n\n{0}\n\n{1}",
            //    //                         ex.Message, ex.StackTrace);
                String^ test = ex->Message;
            }
        }
    };

The commented code above does not work because I think I need an unmanaged wrapper for ALL the simconnect functions that will be used in the program. but I do get a connection with P3D.

edit :

maybe Beatles simconnect managed lib would do the trick

edit2:
no need for Beatle's managed lib. updated code above
 
Last edited:
Hi Ron,
yes is one of the patterns i followed but got stuck into a compiler error:
Code:
#include "stdafx.h"
#include "Form1.h"
#include "SimConnect.h"

using namespace WinFormSimConnect;
using Microsoft.FlightSimulator.SimConnect.dll;
using System.Runtime.InteropServices;

[STAThreadAttribute] int main(array ^args) {
// Enabling Windows XP visual effects before any controls are created
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
// Create the main window and run it
Application::Run(gcnew Form1());
return 0;
}
Compiler output:
Code:
1>WinFormSimConnect.cpp(8): error C2143: syntax error : missing ';' before '.'
1>WinFormSimConnect.cpp(8): error C2873: 'Microsoft' : symbol cannot be used in a using-declaration
1>WinFormSimConnect.cpp(8): error C2059: syntax error : '.'
1>WinFormSimConnect.cpp(9): error C2143: syntax error : missing ';' before '.'
1>WinFormSimConnect.cpp(9): error C2873: 'System' : symbol cannot be used in a using-declaration
1>WinFormSimConnect.cpp(9): error C2059: syntax error : '.'
i guess i would be forced to use the inelegant way.
Beatles lib does not help since is pure c# (i guess)
 
Last edited:
Mario,

ahh ..... this does not look right

using Microsoft.FlightSimulator.SimConnect.dll;

maybe this

using Microsoft.FlightSimulator.SimConnect;

edit:

or were you trying to use

#using <Microsoft.FlightSimulator.SimConnect.dll>

Also ensure all your code is the same .NET version. I have heard sometimes dlls and exe are set to .NET 4.5 or .net 4.0 for VS 2010
 
Last edited:
I have update my code above. It's just a windows form with one button. Code for the button is as above.

Get rid of your line
#include "SimConnect.h". That's unmanaged code. That's the reason you get the errors.

Just do the reference and add the two lines in the using without the .dll suffix.

Remember my example is for P3D v 2.3
 
Thanks again Ron,
sorry no joy,
corrected using Microsoft.FlightSimulator.Simconnect
and got ride of unmanaged simconnect.h and still exactly got same errors.
may be some compilation flag wrongly set ?
Guess better pointing me to your .sln or privately send me via mail at: boss@simskunkworks.com
tia
/Mario
 
Hi Ron,
could compile and link, my error was trivial, omitting the scope resolution operator in Form1.h
using Microsoft::FlightSimulator::SimConnect;
using namespace System::Runtime::InteropServices;
however my program ends with an exception;
"FileLoadException was Unhandled Mixed mode assembly is built against version 'v2.0.50727' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information."
and your ends with a failed "try" to make a new simulation_connection.
Double checked projects properties and they match.
Furthermore, even if i try to set a different reference to Microsoft SimConnect dll , property manager points me always to a non existent:
..\..\..\..\..\Windows\assembly\GAC_32\Microsoft.FlightSimulator.SimConnect\10.0.61259.0__31bf3856ad364e35\Microsoft.FlightSimulator.SimConnect.dll
i'm close to give up :(
/mario
 
v2.0.50727 - this is .NET 2 - forgot - FSX is old so you need to install .NET 2 if you don't have it. What version of windows?? Sorry since I have uninstalled FSX currently - I really can't help too much anymore.

This means you may need to install .NET framework 3.5 - includes 2.0

http://www.microsoft.com/en-us/download/details.aspx?id=22

Do some googling - don't know what your system is - may need to do more reasearch on this issue.
 
Last edited:
Thanks Ron,
i would like forget FSX but we have to develop for it yet :(
I will take the inelegant way...
thanks again for your help.
/Mario
 
Back
Top