• 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.GetLastSentPacketID for managed code?

Messages
639
Country
panama
I was looking at this:

https://msdn.microsoft.com/en-us/library/cc526983.aspx#SimConnect_GetLastSentPacketID

But I can't find it when using managed code (C#). The problem is I am receiving an exception notification on the OnRecvException handler and there is reports a SendID. According to the documentation the way to trace it back is to access GetLastSentPacketId when you send a request. But then I can't find it and therefore it is very difficult to know WHY I am getting a duplicate ID.
 
You can use the SimConnect.dll directly to call that method.
It requires some reflection to get the sim-connect handle out of the managed SimConnect object, but that's no big deal.
I got it working in my code.

Define these in your SimConnect client code (e.g. the Form that holds the SimConnect object):

// To enable extra SimConnect functions.
IntPtr hSimConnect;

// Extra SimConnect functions.
[DllImport("SimConnect.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
private static extern int /* HRESULT */ SimConnect_GetLastSentPacketID (IntPtr hSimConnect, out UInt32 /* DWORD */ dwSendID);​

After constructing your SimConnect object (here in a variable called "simconnect"):

// Get direct access to the SimConnect handle, to use functions otherwise not supported.
FieldInfo fiSimConnect = typeof(SimConnect).GetField("hSimConnect", BindingFlags.NonPublic | BindingFlags.Instance);
hSimConnect = (IntPtr)fiSimConnect.GetValue(simconnect);​

As part of my addSendRecord() method (inspired by the "Tracking Errors" sample):

UInt32 dwSendID;
int iResult = SimConnect_GetLastSentPacketID(hSimConnect, out dwSendID);​

Hopefully that's enough for you to go on.
 
Hi ulatekh,

had the same problem and you solved it...thank you very much for this helpful code snippet although I wasn't able to load the SimConnect.dll at first as it doesn't seem to get loaded into the GAC.

Greets, Benny
 
SimConnect.dll gets loaded into the "Windows side-by-side" directories.
The SDK installer will install 3 different DLLs. I think each one is specific to a version of flight-simulator, i.e. FSX, ESP, or Prepar3D.
I had to figure out which one I need (by trial and error), and then copy it into the directory of my C# executable.
 
Back
Top