The solution I posted here works with strings, it may provide some assistance.
Below are snippets from that code, relevant to your problem.
I submit the initial request using:
var unit = request.Unit;
if (unit?.IndexOf("string") > -1)
{
unit = null;
}
// Fetch the values suitable for transmission to SimConnect
var simReq = new SimVarRequest
{
ID = RequestID++,
Request = request
};
// Submit the SimVar request to SimConnect
simConnect.AddToDataDefinition(simReq.DefID, request.Name, unit, simReq.SimType, 0.0f, SimConnect.SIMCONNECT_UNUSED);
I submit the Data Structure using:
simConnect.RegisterDataDefineStruct<SimVarString>(simReq.DefID);
Finally, below is my model class for SimVarString above:
internal struct SimVarString
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
public string Value;
}
Note: I have not declared the structure with [StructLayout…], only the [MarshalAs…] is required.
Hope this helps…