Prepar3D SimConnect Libraries

== Introduction ==

Prepar3D in contrast to Microsoft, ships SimConnect only as static libraries. This has several problems: * It requires two different libraries for Release and Debug builds * One has to know exactly what other dependencies are necessary during linking * It is not possible to load and resolve the libraries at runtime * ...

In order to avoid the problems above, the static libraries can be linked to shared libraries by some manual preparation and invoking MSVC compiler at command line.

WARNING: I have not found a way to create a simple project (neither qmake nor Visual Studio Project) to perform the linking. So the linker has to be called manually in a cmd.

== Directories ==

  • client\externals\common\include\simconnect\P3D-v4 header file

    • The header file is generated by us (swift) and version dependent.
    • The original headers are in the sub directories.
  • client\externals\win32-msvc\64\lib here we keep the generated dlls like SimConnect.P3D-v4.3.dll

== Header file ==

The header file is a swift specific version. We keep the old header files so we can also find them if needed. For informational purposes we keep a list of files containing the diffs.

Steps: - Copy new P3D files to the respective sub-directory - Find out about the differences: [diff.exe -u 430/SimConnect.h 440/SimConnect.h > SimConnect430_440.txt]{.title-ref} - Update the swift version [SimConnect.h]{.title-ref}

== Link static library into shared library ==

In order to link the SimConnect static libraries into a shared one, we need two inputs:

  1. The shared library itself. The release version is enough - we don't need to convert the debug library since the API is pure C
  2. The list of symbols to export from the shared library. Those are defined in a module definition file (.def).

=== Dump SimConnect API Symbols ===

Regarding point 2, we are interested only in the SimConnect API functions. They usually start with [SimConnect_]{.title-ref}. Use the following command to build a list of SimConnect API functions that are implemented in the static library:

[dumpbin /LINKERMEMBER:1 SimConnect.lib | findstr SimConnect_ > symbols.dat]{.title-ref}

The resulting [symbols.dat]{.title-ref} file will look similar to this:

6CBA2 SimConnect_AICreateEnrouteATCAircraft
6CBA2 SimConnect_AICreateNonATCAircraft
6CBA2 SimConnect_AICreateObjectWithExternalSim
6CBA2 SimConnect_AICreateParkedATCAircraft

From this symbol list, we can now create our module definition file `SimConnect.def`:

LIBRARY    SimConnect.P3D-v4.0.dll

=== Link shared library ===

Finally, we can run our linker command. It requires several input like the machine type, several other dependent Windows libraries, our created SimConnect.def and an output filename that should be equal to the [LIBRARY]{.title-ref} name specified in [SimConnect.def]{.title-ref}.

If you are running the command from a MSVC command prompt, you won't have the necessary Windows SDK library path configured. To do this, you need to add the required path manually to the %LIB% environment variable. It is fine to use the latest Windows 10 SDK. In my case that was:

[set LIB=%LIB%C:Program Files (x86)Windows Kits10Lib10.0.16299.0umx64;C:Program Files (x86)Windows Kits10Lib10.0.16299.0ucrtx64;]{.title-ref}

Finally run the linker command: [cl.exe SimConnect.lib User32.lib Advapi32.lib Ole32.lib Shell32.lib /link /DLL /MACHINE:X64 /def:SimConnect.def /out:SimConnect.P3D-v4.0.dll]{.title-ref}

Last modified 28.06.2020: Add content (0e00ae5)