What is "SimConnect AddToClientDataDefinition" meant for?

I’m experimenting with WASM and SimConnect. I found a lot of valuable information on this forum, and I’m getting my first results. One of these posts is started by @VFRMau an can be found here. There was also a link to some source code on github.

In the main() function, I found the following code extract:

// Map an ID to the Client Data Area.
hr = SimConnect_MapClientDataNameToID(hSimconnect, "EFIS_CDA", ClientDataID);
        
// Add a double to the data definition.
hr &= SimConnect_AddToClientDataDefinition(hSimconnect, DEFINITION_1, SIMCONNECT_CLIENTDATAOFFSET_AUTO, sizeof(data));

// Set up a custom Client Data Area.
hr &= SimConnect_CreateClientData(hSimconnect, ClientDataID, sizeof(data), SIMCONNECT_CLIENT_DATA_REQUEST_FLAG_CHANGED); // This should be SIMCONNECT_CREATE_CLIENT_DATA_FLAG_READ_ONLY, but has same value

// Request the client data periodically.
hr &= SimConnect_RequestClientData(hSimconnect, ClientDataID, REQUEST_1, DEFINITION_1, SIMCONNECT_CLIENT_DATA_PERIOD_SECOND, SIMCONNECT_CLIENT_DATA_REQUEST_FLAG_DEFAULT);

Based on the SimConnect SDK documentation, Events And Data, I understand most of it. Except the second line.

First line is simply mapping a Client Data Area name to an ID. ID’s are a lot more efficient to work with, so instead of using a null terminated string, we can use ClientDataID from now. In that Client Area Data I can now define several data elements (I think we can call them “variables”). In the third line, a data element is created (I spotted a mistake in the code, the flag should be …_READ_ONLY and not …_CHANGED, although they have the same values). In the fourth line, we ask the sim to give us a value of that data element every second, and REQUEST_1 can be used in the DispatchRoutine (not shown here) to identify this data element when it arrives.

But why do we need the second line? There is even not a link with my ClientDataID. In the third line, when we create the Client Area data element, we provide the “sizeof(data)”, so there it’s not relevant I guess. But we use this “DEFINITION_1” in the RequestClientData call.

Can somebody explain?

Hi,
Out of my memory…
It allows to agree with sim connect what sequence of data will be in the data structure. You can call it several times on the same data id to dynamically define your data struct to simconnect. The sample probably works by accident with the constant having the same value than the data id.

C# api is slightly different but maybe you can get an idea reading my code here:
MSFS_HandOnMouse/MainWindow.xaml.cs at 58582f7229d7829e58884855b4a223d4f49cb789 · arnaud-clere/MSFS_HandOnMouse · GitHub

Thanks @DragonSpore52,

In the meantime I acquired a lot more knowledge, and am even writing my own tutorial on this forum with all the things I learned. Thanks for your reply anyway. Looks like an interesting project.