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

MSFS C# SimConnect Windows Form example

rhumbaflappy

Administrator
Staff member
Resource contributor
Attached is a C# windows form example of the MSFS SimConnect.

MSFS .NET requires both the Microsoft.FlightSimulator.SimConnect.dll (.NET) and the SimConnect.dll (native C++) to be in the folder with the finished program. Look near the final lines of TCalc_004.csproj.:
C#:
  <ItemGroup>
    <Content Include=".\SimConnect.dll">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
  </ItemGroup>

This will copy the SimConnect.dll to the finished debug or release folder in VS19.

The code is C# v4.72, I believe, and AnyCPU. It won't work with x86 because the SimConnect.dll is 64-bit.
 

Attachments

  • TCalc_Code.zip
    297.6 KB · Views: 363
I use VS code and I did <PlatformTarget> x64
You can also use PreserveNewest instead of Always, not that it matters really.

Also for anyone reading this that uses VS Code or otherwise, if you keep SDK in a folder somewhere else you can use:


C#:
  <ItemGroup>
    <ContentWithTargetPath Include="$(MSFS_SDK)/SimConnect SDK/lib/SimConnect.dll">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <TargetPath>SimConnect.dll</TargetPath>
    </ContentWithTargetPath>
  </ItemGroup>

edited: to use the evironment variable forgot I had done that. I installed from MSFS2020 dev mode installer and it set an environment variable MSFS_SDK
 
Last edited:
you can place this in Visual Studio (config) Build Events and it will copy the files when you build a new version.

xcopy "C:\MSFS SDK\SimConnect SDK\lib\SimConnect.dll" "$(TargetDir)" /y
xcopy "C:\MSFS SDK\Samples\SimvarWatcher\SimConnect.cfg" "$(TargetDir)" /y
 
Top