Pete,
first of all, thanks for that outstanding piece of software called FSUIPC... I've been playing with it for a few days now and tried to use it with C# (I know, I know, you don't use C#...)
The C# Code contained in the SDK works fine - it just left me with one problem: I was unable to retrieve and values that you defined as FLOAT (i.e. AI Traffic Block LAT, LON, ALT) with the FSUIPC_Get methods provided.
I have been pushing if forwards and backwards and finally wrote myself another method overload for FSUIPC_Get to handle floats.
public bool FSUIPC_Get(ref int Token, ref float Result)
{
int Size = 4; // 2 bytes in an int
float[] myFloat = new float[1];
if ((Token < 0) || (Token > IPC_BUFFER_SIZE - (4 + Size)) )
{ //Token out of range
Result = 0;
return false;
}
IntPtr heapbuf = Marshal.AllocHGlobal(Size);
Marshal.Copy(IPC, Token + 4, heapbuf, 4);
Marshal.Copy(heapbuf, myFloat, 0, 1 );
Result = myFloat[0];
Marshal.FreeHGlobal(heapbuf);
if (IPCdr[Token] )
{
IPCdr[Token] = false;
return true;
}
else
{ // if (data ready flag not set, function returns false and value found
return false;
}
}
Now, most of the code is a simple copy from one of the existing ones - I just adopted the following section
IntPtr heapbuf = Marshal.AllocHGlobal(Size);
Marshal.Copy(IPC, Token + 4, heapbuf, 4);
Marshal.Copy(heapbuf, myFloat, 0, 1 );
Result = myFloat[0];
and of course had to define
float[] myFloat = new float[1];
.
Unfortunately, the Marshal.Copy does only provide an overload for a float[] Array - not a single float, hence that funny one-element array.
To make a long story short: it works - I can now define a float variable in the code, pass it to FSUIPC_Get and get the proper results from the AI Traffic tables.
What I want to know: is there any other (simpler) way and how have others using C# overcome my initial problem of not being able to read a float properly...
Any thoughts are welcome - I want to learn...
Andreas