Hi Teo,
The following are the formulas I use in VB to get Altitude in MSL and Ground (RADAR) Altitude.
'Altitude in MSL
Dim BaroCorr As Long, AtmosCorr As Long, CorrDiff As Single
Dim lngAltitude As Long, lngMeterAlt1 As Long, lngMeterAlt2 As Long, lngMillibars as Long, lngPressQNH as Long
Dim lngGrdAlt As Long
'Use the following offsets for Altitude MSL
'I store each offset value in a long integer
'The following is not code; it is only intended to identify the offsets you need
lngMillibars = &H330 (Size 2, 16-bit)
lngPressQNH = &HEC6 (Size 2, 16-bit)
lngMeterAlt1 = &H570 (Size 4, 32-bit)
lngMeterAlt2 = &H574 (Size 4, 32-bit)
BaroCorr = (145442.2 * (1 - (((lngMillibars / 16) * 0.02953) / 29.92126) ^ 0.190261)) 'correction due to the baro setting
AtmosCorr = (145442.2 * (1 - (((lngPressQNH / 16) * 0.02953) / 29.92126) ^ 0.190261)) 'correction due to the actual atmospheric pressure
CorrDiff = BaroCorr - AtmosCorr
lngAltitude = Round((lngMeterAlt1 * 3.28084 / 4294967296#) + (lngMeterAlt2 * 3.28084), 4) - CorrDiff
'for Ground Altitude
lngGrdAlt = &H20 (Size 4, 32-bit)
AGL_Alt = Round(lngAltitude + CorrDiff, 0) - (Round(((lngGrdAlt / 256) * 3.2808) + 12, 0))
This may seem a little complicated but if you can get it to work, I think you'll see it accomplishes everything that you need. The corrections are necessary in MS flight sim to avoid erroneous ground altitude readings when the altimeter is not set correctly. In real aircraft radar altitude display is not be affected by baro settings.
Hope this helps.