- Messages
- 3
- Country

Can anyone take a look at the code below, I cannot firgure out for the life of me why I am getting random values?
Code:
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
#include <strsafe.h>
#include "SimConnect.h"
HANDLE hSimConnect = NULL;
int quit = 0;
static enum CONTROLS_DATA_ID {
DEFINITION_CONTROLS
};
static enum CONTROLS_REQUEST_ID {
REQUEST_CONTROLS
};
struct controls
{
double ypos;
double xpos;
};
//callback procedure
void CALLBACK MyDispatchProc(SIMCONNECT_RECV* pData, DWORD cbData, void *pContext)
{
HRESULT hr;
//check events
switch (pData->dwID)
{
case SIMCONNECT_RECV_ID_SIMOBJECT_DATA:
{
SIMCONNECT_RECV_SIMOBJECT_DATA *pObjData = (SIMCONNECT_RECV_SIMOBJECT_DATA*)pData;
switch (pObjData->dwRequestID)
{
case REQUEST_CONTROLS:
{
controls *pS = (controls*)&pObjData->dwData;
system("CLS");
printf("x value: %d\n", pS->xpos);
printf("y value: %d\n", pS->ypos);
break;
}
default:
break;
}
break;
}
}
}
int __cdecl _tmain(int argc, _TCHAR* argv[])
{
//create connection to FSX and error check
HRESULT hr = SimConnect_Open(&hSimConnect,"Steve's Autopilot",NULL,0,0,0);
if (hr == S_OK)
{
printf("Connected to FSX!\n");
}
else
{
printf("Failed to connect to FSX!\n");
return 1;
}
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_CONTROLS, "YOKE Y POSITION", "percent");
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_CONTROLS, "YOKE X POSITION", "percent");
//request data from throttle position
hr = SimConnect_RequestDataOnSimObject(hSimConnect,
REQUEST_CONTROLS,
DEFINITION_CONTROLS,
SIMCONNECT_OBJECT_ID_USER,
SIMCONNECT_PERIOD_VISUAL_FRAME);
if (hr != S_OK)
{
printf("Could not receive aircraft data!\n");
}
//loop until quit message
while (quit == 0)
{
SimConnect_CallDispatch(hSimConnect, MyDispatchProc, NULL);
Sleep(1);
}
//close connection to FSX
hr = SimConnect_Close(hSimConnect);
return 0;
}
