FSX SimConnect.GetLastSentPacketID for managed code?

#1
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.
 
#2
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.
 
#3
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
 
#4
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.
 
Top