hi all, im beginning with sim connect, and i need to get some flight variables. I'vw started with one of SimConnect SDK samples, its called Request Data.
I think It is the closest i want to do.
it's supossed after the program receives simstart event, the switch in the callback function receives SIMCONNECT_RECV_ID_SIMOBJECT_DATA_BYTYPE
that will print the values of these variables.
As far as i 've tried, the program enter in the while loop and receive the simstart event, but i've never seen anymore info printed
could anyone help me?
I think It is the closest i want to do.
Code:
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
#include <strsafe.h>
#include "SimConnect.h"
int quit = 0;
HANDLE hSimConnect = NULL;
struct Struct1
{
char title[256];
double kohlsmann;
double altitude;
double latitude;
double longitude;
};
static enum EVENT_ID{
EVENT_SIM_START,
};
static enum DATA_DEFINE_ID {
DEFINITION_1,
};
static enum DATA_REQUEST_ID {
REQUEST_1,
};
void CALLBACK MyDispatchProcRD(SIMCONNECT_RECV* pData, DWORD cbData, void *pContext)
{
HRESULT hr;
printf("callback llamado\n");
switch(pData->dwID)
{
case SIMCONNECT_RECV_ID_EVENT:
{
SIMCONNECT_RECV_EVENT *evt = (SIMCONNECT_RECV_EVENT*)pData;
switch(evt->uEventID)
{
case EVENT_SIM_START:
// Now the sim is running, request information on the user aircraft
hr = SimConnect_RequestDataOnSimObjectType(hSimConnect, REQUEST_1, DEFINITION_1, 0, SIMCONNECT_SIMOBJECT_TYPE_USER);
break;
default:
break;
}
break;
}
case SIMCONNECT_RECV_ID_SIMOBJECT_DATA_BYTYPE:
{
SIMCONNECT_RECV_SIMOBJECT_DATA_BYTYPE *pObjData = (SIMCONNECT_RECV_SIMOBJECT_DATA_BYTYPE*)pData;
switch(pObjData->dwRequestID)
{
case REQUEST_1:
{
DWORD ObjectID = pObjData->dwObjectID;
Struct1 *pS = (Struct1*)&pObjData->dwData;
if (SUCCEEDED(StringCbLengthA(&pS->title[0], sizeof(pS->title), NULL))) // security check
{
printf("\nObjectID=%d Title=\"%s\"\nLat=%f Lon=%f Alt=%f Kohlsman=%.2f", ObjectID, pS->title, pS->latitude, pS->longitude, pS->altitude, pS->kohlsmann );
}
break;
}
default:
break;
}
break;
}
case SIMCONNECT_RECV_ID_QUIT:
{
quit = 1;
break;
}
default:
printf("\nReceived:%d",pData->dwID);
break;
}
}
void testDataRequest()
{
HRESULT hr;
if (SUCCEEDED(SimConnect_Open(&hSimConnect, "Request Data", NULL, 0, 0, 0)))
{
printf("\nConnected to Flight Simulator!\n");
// Set up the data definition, but do not yet do anything with it
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_1, "Title", NULL, SIMCONNECT_DATATYPE_STRING256);
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_1, "Kohlsman setting hg", "inHg");
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_1, "Plane Altitude", "feet");
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_1, "Plane Latitude", "degrees");
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_1, "Plane Longitude", "degrees");
// Request an event when the simulation starts
hr = SimConnect_SubscribeToSystemEvent(hSimConnect, EVENT_SIM_START, "SimStart");
int i=0;
while( 0 == quit )
{
if(i%500 == 0)
printf("%i\n",i);
SimConnect_CallDispatch(hSimConnect, MyDispatchProcRD, NULL);
Sleep(1);
i++;
}
hr = SimConnect_Close(hSimConnect);
printf("adios\n");
}
}
int __cdecl _tmain(int argc, _TCHAR* argv[])
{
testDataRequest();
return 0;
}
it's supossed after the program receives simstart event, the switch in the callback function receives SIMCONNECT_RECV_ID_SIMOBJECT_DATA_BYTYPE
that will print the values of these variables.
As far as i 've tried, the program enter in the while loop and receive the simstart event, but i've never seen anymore info printed
could anyone help me?

