0

How do you use variables within structures in C++?

I'd like to move the data to a Winform textbox and to USB variables.

Tried several string conversion techniques, but I'm not referring to the structure element properly, I keep getting all sorts of errors.

I'd like to get to the contents that were just copied to FLIGHTDATA.

// Assign data to structure
     pObjData = (SIMCONNECT_RECV_SIMOBJECT_DATA*)pData;
     if (pData->dwID == SIMCONNECT_RECV_ID_SIMOBJECT_DATA && pObjData->dwRequestID == REQUEST_1)
         {
              FlightData = (Struct1*)&pObjData->dwData;

This is where FlightData is defined:

struct Struct1
{
    public:double RPM_Indicator;
//  double ADFMode;
};

//Struct1 LvarList;

SIMCONNECT_RECV_SIMOBJECT_DATA* pObjData = NULL;
SIMCONNECT_RECV* pData = NULL;
DWORD cbData = 0;
Struct1* FlightData = NULL;
bool bDone = false;

It's RPM_Indicator that interests me.

1. What technique do I use to convert it to a string? 2. I'd also like to learn how to truncate decimals.

Thanks!

Robert


SOLUTION:

It helps when you learn how to properly refer to the structure element, and to know how to convert types. Thank you google.

int intEngineRPM = int(FlightData->RPM_Indicator);
this->tbRPM->Text = intEngineRPM.ToString();

Robert :)

Robert H
  • 1
  • 1
  • Your first question is not clear ? What do you want to convert to string ? if you are talking about the RPM_Indicator which is double you can use `sprintf` with the desired format. Concerning the second question you might find the answer in [this post](https://stackoverflow.com/questions/304011/truncate-a-decimal-value-in-c) – M. Yousfi May 22 '23 at 08:21
  • I asked how do you use a variable that is within a structure 'cause I can't just use RPM_Indicator; it offers me choices, and none are the actual value. [img]https://i.imgur.com/XPpZ3ut.png[/img] If I try to use RPM_Indicator alone, it generates an "E0020 error; undefined". I have to use what they put into Flight Data. I've tried a multitude of variations of SPRINTF and other ways, none worked. Unless I'm not using the proper parameters. [img]https://i.imgur.com/XuXLjks.png[/img] The value of 1126 is correct. Robert – Robert H May 22 '23 at 19:03
  • UPDATE: Thanks to Google I can now read a structure element into a Double, but I just moved the problem elsewhere cause I still can't do anything with the Double. Can't display on GUI, can't convert to string... [img]https://i.imgur.com/e69lLjq.png[/img] – Robert H May 22 '23 at 23:34

0 Answers0