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

FSX SimConnect_CallDispatch in managed code

KWB

Messages
69
Country
germany
I wonder whether there is no equivalent of SimConnect_CallDispatch in the managed code library. Do I just miss it, is it not required, or what would I do if the equivalent C++ code shows such a call?
 
Hi,

CallDispatch is not used with managed code : see the SDK doc on managed code programming and also the samples :

// Simconnect client will send a win32 message when there is
// a packet to process. ReceiveMessage must be called to
// trigger the events. This model keeps simconnect processing on the main thread.

protected override void DefWndProc(ref Message m)
{
if (m.Msg == WM_USER_SIMCONNECT)
{
if (simconnect != null)
{
simconnect.ReceiveMessage();
}
}
else
{
base.DefWndProc(ref m);
}
}
 
Thanks for helping me on this, and sorry if I have missed some obvious documentation. Actually to what documentation you are referring to? I am using this one here, anything better / more detailed?

What I have basically done is to "translate" the "Menu Items" example to C#. Eventually I have used simconnect.ReceiveDispatch(this.DispatchProc); in order to replace SimConnect_CallDispatch(hSimConnect, MyDispatchProcMI, NULL); from the C++ example.

BTW, is overriding DefWndProc working if the client with SimConnect is running on a remote computer?
 
Last edited:
For the documentation, I use the fsxsdk.chm file that is contained in the SDK folder. But I guess it is the same contain that is in your link.

Rather thant trying to translate a C++ program into c#, I would suggest that you start from one of the managed C# code samples of the SDK and add the API that you need if they are not present in the sample.

Roughly, the process is the following :

- do the DefWndProc overide. If you are not in a Windows Form program, a simple loop with ReceiveMessage is ok. for instance :
while (!_isEnded)
{
_simConnect.ReceiveMessage();
Thread.Sleep(1);
}

- During the initialization phase, register handlers for the appropriate events. For instance :

simconnect.OnRecvException += new SimConnect.RecvExceptionEventHandler(simconnect_OnRecvException);

- Program the processing of each events : Example :
void simconnect_OnRecvException(SimConnect sender, SIMCONNECT_RECV_EXCEPTION data)
{
displayText("Exception received: " + data.dwException);
}

In conclusion, the structure of the program is very similar to a windows form program in C#.

SimConnect client can be used on a remote computer (but setting the parameters may be a little tricky).

Best regards.

Patrick.
 
Yep, it is working correctly on a remote computer, thanks for pointing me in the right direction!
 
Back
Top