1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

FSX SimConnect.GetLastSentPacketID for managed code?

Discussion in 'SimConnect' started by lordofwings, 30 Sep 2016.

Tags:
  1. lordofwings

    lordofwings

    Joined:
    5 Nov 2006
    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.
     
  2. ulatekh

    ulatekh

    Joined:
    27 Sep 2017
    Messages:
    1
    Country:
    us-arizona
    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.
     

Share This Page