SimConnect_GetNextDispatch

The SimConnect_GetNextDispatch function is used to process the next SimConnect message received, without the use of a callback function.

 

Syntax
HRESULT SimConnect_GetNextDispatch(
    HANDLE  hSimConnect,
    SIMCONNECT_RECV**  ppData,
    DWORD*  pcbData
    );

 

Parameters
Parameter Description Type
hSimConnect Handle to a SimConnect object. Integer
ppData Pointer to a pointer to a data buffer, initially to be treated as a SIMCONNECT_RECV structure. If you are going to make a copy of the data buffer (which is maintained by the SimConnect client library) make sure that the defined buffer is large enough (the size of the returned data structure is one member of the SIMCONNECT_RECV structure. Integer
pcbData Pointer to the size of the data buffer, in bytes. Integer

 

Return Values

The function returns an HRESULT. Possible values include, but are not limited to, those in the following table.

Return value Description
S_OK The function succeeded.
E_FAIL The function failed.

 

Example
SIMCONNECT_RECV* pData;
DWORD cbData;
 
hr = SimConnect_GetNextDispatch(hSimConnect, &pData, &cbData);
if (SUCCEEDED(hr))
{
    switch(pData->dwID)
        { 
        case SIMCONNECT_RECV_ID_OPEN: 
            SIMCONNECT_RECV_OPEN *openData = (SIMCONNECT_RECV_OPEN*) pData;
            break;
        case SIMCONNECT_RECV_ID_EVENT: 
            SIMCONNECT_RECV_EVENT *evt = (SIMCONNECT_RECV_EVENT*) pData;
            break;
        case SIMCONNECT_RECV_ID_EVENT_FILENAME:
            SIMCONNECT_RECV_EVENT_FILENAME *evt = (SIMCONNECT_RECV_EVENT_FILENAME*) pData;
            break;
        case SIMCONNECT_RECV_ID_EVENT_OBJECT_ADDREMOVE:
            SIMCONNECT_RECV_EVENT_OBJECT_ADDREMOVE *evt = (SIMCONNECT_RECV_EVENT_OBJECT_ADDREMOVE*) pData;
            break;
        case SIMCONNECT_RECV_ID_EVENT_FRAME:
            SIMCONNECT_RECV_EVENT_FRAME *evt = (SIMCONNECT_RECV_EVENT_FRAME*) pData;
            break;
        case SIMCONNECT_RECV_ID_SIMOBJECT_DATA:
            SIMCONNECT_RECV_SIMOBJECT_DATA *pObjData = (SIMCONNECT_RECV_SIMOBJECT_DATA*) pData;
            break;
        case SIMCONNECT_RECV_ID_SIMOBJECT_DATA_BYTYPE:
            SIMCONNECT_RECV_SIMOBJECT_DATA_BYTYPE *pObjData = (SIMCONNECT_RECV_SIMOBJECT_DATA_BYTYPE*) pData; 
            break;
        case SIMCONNECT_RECV_ID_QUIT:
            break;
        case SIMCONNECT_RECV_ID_EXCEPTION:
            SIMCONNECT_RECV_EXCEPTION *except = (SIMCONNECT_RECV_EXCEPTION*) pData;
            break;
        case SIMCONNECT_RECV_ID_WEATHER_OBSERVATION:
            SIMCONNECT_RECV_WEATHER_OBSERVATION* pWxData = (SIMCONNECT_RECV_WEATHER_OBSERVATION*) pData;
            const char* pszMETAR = (const char*) (pWxData+1);
            break;
        default:
            break;
        }
    }

 

Remarks

It is important to call this function sufficiently frequently that the queue of information received from the server is processed. If there are no messages in the queue, the [dwID] parameter will be set to SIMCONNECT_RECV_ID_NULL.

 

See Also