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

FSW Flight sim world and sim connect 64 bit

Hacking, or did you just dynamically load the DLL and get the functions in the same format as the old SimConnect (with LoadLibrary() and GetProcAddress())?
 
Okay, I got my SimConnect DLL project converted over. It connects to FSW just fine, appears in the addon menu, receives data and events, etc. I haven't tested every SimConnect function though.

The instructions how to do it are at the top of the attached file, but basically save the whole thing as a new header file, and include that instead of simconnect.h (and don't link to simconnect.lib). It's basically FSX's simconnect.h except the linked functions are wrapped in a class called CFSWSimConnect that extracts them out of SimConnect.dll at runtime.

Then in your project you create an instance (e.g. CFSWSimConnect SimConnect) that everybody who needs it can see, and find-and-replace SimConnect_ with SimConnect. ("dot") to call the new class instead of the function.

Then recompile your project to 64 bits (in Visual Studio 2015, right-click the project name in solution explorer, Properties, under Platform choose "x64", make sure the include directories, output path, and any other settings you changed in the Win32 platform are correct, apply, then in the top toolbar change the Solutions Platform window to "x64", cross your fingers and build).

If you're doing voodoo with pointers and funny casting tricks you may run into problems, but I only had a few type conversion warnings going to 64 bit that were easily fixed.
 

Attachments

I adopted the code from here http://www.fsdeveloper.com/wiki/index.php?title=SimConnect_-_Accessing_from_VB and successfully connected VB with FSW.
Code:
    <DllImport("SimConnect.dll", CallingConvention:=CallingConvention.StdCall, CharSet:=CharSet.Ansi)>
    Shared Function SimConnect_AddToDataDefinition(
                                                  ByVal hSimConnect As Int32,
                                                  ByVal DefineID As Int32,
                                                  ByVal DatumName As String,
                                                  ByVal UnitsName As String,
                                                  ByVal DatumType As Int32,
                                                  Optional ByVal fEpsilon As Single = 0,
                                                  Optional ByVal DatumID As Int32 = 0) As Int32
    End Function

    <DllImport("SimConnect.dll", CallingConvention:=CallingConvention.StdCall, CharSet:=CharSet.Ansi)>
    Shared Function SimConnect_Open(ByRef hSimConnect As UInt32, ByVal AppName As String, ByVal hWnd As UInt32, ByVal UserEventWin32 As UInt32, ByVal hEventHandle As UInt32, ByVal ConfigIndex As UInt32) As UInt32
    End Function

    <DllImport("SimConnect.dll", CallingConvention:=CallingConvention.StdCall, CharSet:=CharSet.Ansi)>
    Shared Function SimConnect_GetNextDispatch(ByVal hSimConnect As Int32, ByRef ppData As IntPtr, ByRef pcbData As IntPtr) As Int32
    End Function

    <DllImport("SimConnect.dll", CallingConvention:=CallingConvention.StdCall, CharSet:=CharSet.Ansi)>
    Shared Function SimConnect_RequestDataOnSimObject(ByVal hSimConnect As Int32,
                                                      ByVal SIMCONNECT_DATA_REQUEST_ID As Int32,
                                                      ByVal SIMCONNECT_DATA_DEFINITION_ID As Int32,
                                                      ByVal SIMCONNECT_OBJECT_ID As Int32,
                                                      ByVal SIMCONNECT_DATA_REQUEST_FLAG As Int32,
                                                      ByVal origin As Int32,
                                                      ByVal interval As Int32,
                                                      ByVal limit As Int32) As Int32
    End Function

    <DllImport("SimConnect.dll", CallingConvention:=CallingConvention.StdCall, CharSet:=CharSet.Ansi)>
    Shared Function SimConnect_RequestDataOnSimObjectType _
      (ByVal hSimConnect As UInt32,
       ByVal RequestID As Int32,
       ByVal DefineID As UInt32,
       ByVal dwRadiusMeters As UInt32,
       ByVal ObjectType As UInt32) As UInt32
    End Function

    <DllImport("SimConnect.dll", CallingConvention:=CallingConvention.StdCall, CharSet:=CharSet.Ansi)>
    Shared Function SimConnect_Close(ByVal hSimConnect As Int32) As Int32
    End Function
    Structure SIMCONNECT_RECV_OPEN
        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=256)>
        Dim szApplicationName As String
        Dim dwApplicationVersionMajor As Int32
        Dim dwApplicationVersionMinor As Int32
        Dim dwApplicationBuildMajor As Int32
        Dim dwApplicationBuildMinor As Int32
        Dim dwSimConnectVersionMajor As Int32
        Dim dwSimConnectVersionMinor As Int32
        Dim dwSimConnectBuildMajor As Int32
        Dim dwSimConnectBuildMinor As Int32
        Dim dwReserved1 As Int32
        Dim dwReserved2 As Int32
    End Structure
Replace
Code:
CopyMemory Recv, ByVal pData, Len(Recv)
pData = pData + Len(Recv)
with
Code:
Recv = Marshal.PtrToStructure(pData, GetType(SIMCONNECT_RECV))
pData = pData + Marshal.SizeOf(Recv)
etc.
 
Attached is a dumpbin output of SimConnect.dll... it might be of some use.
 

Attachments

Hi @rhumbaflappy
Here is an example project for VS2015. Make sure the DllImports show the correct path to the location of your SimConnect_x86.dll
<DllImport("D:\Games\Steam\SteamApps\common\FSW\SimConnect_x86.dll", CallingConvention:=CallingConvention.StdCall, CharSet:=CharSet.Ansi)>. Start FSW, FSW_SimConnect.exe and then click on the Start button. Please let me know if it works.
 

Attachments

Works!
Altered code:
<DllImport("SimConnect_x86.dll", CallingConvention:=CallingConvention.StdCall, CharSet:=CharSet.Ansi)>

And copied SimConnect_x86.dll to the same folder. Also, it compiled as 64-bit with SimConnect.dll and works fine, with that DLL copied to the same folder. I used VS2017 Community. Very nice work.
 
I rewrote TCalcX as TCalcFSW, and have a working solution for FSW in 64 bits. Many thanks to "value1". Code included for Visual Studio Community 2017 (written as C#):
 

Attachments

A post by vincent32 got me thinking about setting a SLEW command to FSW:

C++:
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
#include "SimConnect.h"
#include <strsafe.h>

int quit = 0;
HANDLE hSimConnect = NULL;

static enum GROUP_ID {
    MyGroup,
};

static enum EVENT_ID {
    EVENT_SLEW_ON,
};


void testSendEvent()
{
    HRESULT hr;

    if (SUCCEEDED(SimConnect_Open(&hSimConnect, "FSW Slew", NULL, 0, 0, 0)))
    {
        MessageBox(NULL, _T("SimConnected! \n \n Mapping the Client event... \n \n Transmitting the Client event..."), _T(""), MB_OK | MB_SYSTEMMODAL);

        hr = SimConnect_MapClientEventToSimEvent(hSimConnect, EVENT_SLEW_ON, "SLEW_ON");
        hr = SimConnect_AddClientEventToNotificationGroup(hSimConnect, MyGroup, EVENT_SLEW_ON);
        hr = SimConnect_SetNotificationGroupPriority(hSimConnect, MyGroup, SIMCONNECT_GROUP_PRIORITY_HIGHEST);

        SimConnect_TransmitClientEvent(hSimConnect, 0, EVENT_SLEW_ON, 0, SIMCONNECT_GROUP_PRIORITY_HIGHEST, SIMCONNECT_EVENT_FLAG_GROUPID_IS_PRIORITY);

        MessageBox(NULL, _T("Slew set!"), _T(""), MB_OK | MB_SYSTEMMODAL);

        hr = SimConnect_Close(hSimConnect);
    }
}

//int __cdecl _tmain(int argc, _TCHAR* argv[])

// Hides the console window
int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
    testSendEvent();
    return 0;
}

Change the 'Start in" path in the shortcut I made to your root FSW folder, and you won't need to copy the SimConnect.dll:

FSWSlew.png



This thread https://www.fsdeveloper.com/forum/threads/c-clr-windows-forms.442294/ has a Windows Form C++/CLR version.
 

Attachments

Last edited:
Back
Top