Forums Neueste Beiträge
 

c++ struct übersetzen

12/08/2008 - 08:21 von Stefan Simon | Report spam
Hallo,

ich habe folgendes c++ struct

\\\
typedef struct {//BMSD = Bonito Meteo Server Data BMSD_SFC+BMSD_SEA
USHORT prmsl; //PRMSL 0.1 of Pressure [hPa] +900.0 hPa
short temp; //TMP 0.1 of Temperature [C] (2m level)
short wtemp; //WTMP 0.1 of Water Temperature [C] (surface level)
union
{
USHORT wind; //WIND 0.1 of Wind speed [m/s] (p.ex. used by MeteoTools
GetDataOfPoint)
short ugrd; //vector-U value of wind (10m Level)
};
union
{
USHORT wdir; //WDIR 0.1 of Wind direction [deg] (p.ex. used by
MeteoTools GetDataOfPoint)
short vgrd; //vector-V value of wind (10m Level)
};

BYTE btcdc; //BTCDC Boundary cloud layer total cloud cover [%]
BYTE tcdc; //TCDC Convective cloud layer total cloud cover [%]
BYTE rh; //RH Relative humidity [%]
BYTE pflag; //flags type of precipitation and land and ice cover (see
FRC_ICEC,FRC_RAIN.)
//BIT-0 ICEC Ice cover (ice=1, no ice=0)
//BIT-1 CRAIN 3 hr average Categorical rain (yes=1; no=0) [non-dim]
//BIT-2 CFRZR 3 hr average Categorical freezing rain (yes=1; no=0)
[non-dim]
//BIT-3 CICEP 3 hr average Categorical ice pellets (yes=1; no=0)
[non-dim]
//BIT-4 CSNOW 3 hr average Categorical snow (yes=1; no=0) [non-dim]

USHORT weasd; //WEASD 0.1 of equivalent of accumulated snow depth
[kg/m^2]
USHORT acpt; //ACPT 0.1 of precipitation [kg/m^2]

USHORT htsgw; //HTSGW 0.1 of Sig height of wind waves and swell [m]
USHORT wvper; //WVPER 0.1 of Mean period of wind waves [s]
USHORT wvdir; //WVDIR 0.1 of Direction of wind waves [deg]
USHORT perpw; //PERPW 0.1 of Primary wave mean period [s]
USHORT dirpw; //DIRPW 0.1 of Primary wave direction [deg]
USHORT persw; //PERSW 0.1 of Secondary wave mean period [s]
USHORT dirsw; //DIRSW 0.1 of Secondary wave direction [deg]
}BMSDATA_SET;
///

und daraus habe ich folgendes gemacht:

\\\
<StructLayout(LayoutKind.Explicit)> _
Private Structure TWind
<FieldOffset(0)> Friend Value As UShort
<FieldOffset(2)> Friend grd As Short
End Structure

<StructLayout(LayoutKind.Explicit)> _
Private Structure BMSDATA_SET
<FieldOffset(0)> Friend prmsl As UShort
<FieldOffset(2)> Friend temp As Short
<FieldOffset(4)> Friend wtemp As Short

<FieldOffset(6)> Friend WindSpeed As TWind
<FieldOffset(10)> Friend WindDirection As TWind

<FieldOffset(14)> Friend btcdc As Byte
<FieldOffset(15)> Friend tcdc As Byte
<FieldOffset(16)> Friend rh As Byte
<FieldOffset(17)> Friend pflag As Byte

<FieldOffset(18)> Friend weasd As UShort
<FieldOffset(20)> Friend acpt As UShort

<FieldOffset(22)> Friend htsgw As UShort
<FieldOffset(24)> Friend wvper As UShort
<FieldOffset(26)> Friend wvdir As UShort
<FieldOffset(28)> Friend perpw As UShort
<FieldOffset(30)> Friend dirpwas As UShort
<FieldOffset(32)> Friend persw As UShort
<FieldOffset(34)> Friend dirsw As UShort

End Structure ' /BMSDATA_SET;
///


Der Dll-Aufruf sieht wie folgt aus:

' BOOL GetDataOfPoint(int lon,int lat, BMSDATA_SET* set)
<DllImport("MeteoTools")> _
Private Shared Function GetDataOfPoint(ByVal Latitude As Int32, ByVal
Longitude As Int32, ByRef Out As BMSDATA_SET) As Boolean
End Function

Ein Aufruf dieser Function gibt jedoch false zurück. Nun weiß ich nicht, ob
das an der Structure oder an anderen Dingen liegt.
Kann mir jemand sagen, ob die Structure so korrekt ist und ich woanders
weitersuchen muss?

die Structur gibts hier nochmal im Original:
http://www.meteoserver.net/Developm...teoDataSet

und die dazu gehörige function:
http://www.meteoserver.net/Developm...aPoint.htm

tia,
Stefan
 

Lesen sie die antworten

#1 Karsten Sosna
12/08/2008 - 10:16 | Warnen spam
und daraus habe ich folgendes gemacht:

\\\
<StructLayout(LayoutKind.Explicit)> _
Private Structure TWind
<FieldOffset(0)> Friend Value As UShort
<FieldOffset(2)> Friend grd As Short
End Structure

<StructLayout(LayoutKind.Explicit)> _
Private Structure BMSDATA_SET
<FieldOffset(0)> Friend prmsl As UShort
<FieldOffset(2)> Friend temp As Short
<FieldOffset(4)> Friend wtemp As Short

<FieldOffset(6)> Friend WindSpeed As TWind
<FieldOffset(10)> Friend WindDirection As TWind

<FieldOffset(14)> Friend btcdc As Byte
<FieldOffset(15)> Friend tcdc As Byte
<FieldOffset(16)> Friend rh As Byte
<FieldOffset(17)> Friend pflag As Byte

<FieldOffset(18)> Friend weasd As UShort
<FieldOffset(20)> Friend acpt As UShort

<FieldOffset(22)> Friend htsgw As UShort
<FieldOffset(24)> Friend wvper As UShort
<FieldOffset(26)> Friend wvdir As UShort
<FieldOffset(28)> Friend perpw As UShort
<FieldOffset(30)> Friend dirpwas As UShort
<FieldOffset(32)> Friend persw As UShort
<FieldOffset(34)> Friend dirsw As UShort

End Structure ' /BMSDATA_SET;
///


Hallo Stefan,
ich glaube Du hast die Union's falsch übersetzt. Hier meine Version(ohne
Gewàhr):
\\\
Imports System.Runtime.InteropServices
<StructLayout(LayoutKind.Sequential)> _
Public Structure BMSDATA_SET ' struct {//BMSD = Bonito Meteo Server Data
BMSD_SFC+BMSD_SEA
<FieldOffset(0)> Public prmsl As UInt16 '//PRMSL 0.1 of Pressure [hPa]
+900.0 hPa
<FieldOffset(2)> Public temp As Int16 '//TMP 0.1 of Temperature [C] (2m
level)
<FieldOffset(4)> Public wtemp As Int16 '//WTMP 0.1 of Water Temperature
[C] (surface level)

'Union
<FieldOffset(6)> Public wind As UInt16 '//WIND 0.1 of Wind speed
[m/s] (p.ex. used by MeteoTools GetDataOfPoint)
<FieldOffset(6)> Public ugrd As Int16 '//vector-U value of wind (10m
Level)
'/Union

'Union
<FieldOffset(8)> Public wdir As UInt16 '//WDIR 0.1 of Wind direction
[deg] (p.ex. used by MeteoTools GetDataOfPoint)
<FieldOffset(8)> Public vgrd As Int16 '//vector-V value of wind (10m
Level)
'/Union

<FieldOffset(10)> Public btcdc As Byte '//BTCDC Boundary cloud layer
total cloud cover [%]
<FieldOffset(11)> Public tcdc As Byte '//TCDC Convective cloud layer
total cloud cover [%]
<FieldOffset(12)> Public rh As Byte '//RH Relative humidity [%]
<FieldOffset(13)> Public pflag As Byte '//flags type of precipitation
and land and ice cover (see FRC_ICEC,FRC_RAIN.)

<FieldOffset(14)> Public weasd As UInt16 '//WEASD 0.1 of equivalent of
accumulated snow depth [kg/m^2]
<FieldOffset(16)> Public acpt As UInt16 '//ACPT 0.1 of precipitation
[kg/m^2]
<FieldOffset(18)> Public htsgw As UInt16 '//HTSGW 0.1 of Sig height of
wind waves and swell [m]
<FieldOffset(20)> Public wvper As UInt16 '//WVPER 0.1 of Mean period of
wind waves [s]
<FieldOffset(22)> Public wvdir As UInt16 '//WVDIR 0.1 of Direction of
wind waves [deg]
<FieldOffset(24)> Public perpw As UInt16 '//PERPW 0.1 of Primary wave
mean period [s]
<FieldOffset(26)> Public dirpw As UInt16 '//DIRPW 0.1 of Primary wave
direction [deg]
<FieldOffset(28)> Public persw As UInt16 '//PERSW 0.1 of Secondary wave
mean period [s]
<FieldOffset(30)> Public dirsw As UInt16 '//DIRSW 0.1 of Secondary wave
direction [deg]
End Structure
///

Der Dll-Aufruf sieht wie folgt aus:

' BOOL GetDataOfPoint(int lon,int lat, BMSDATA_SET* set)
<DllImport("MeteoTools")> _
Private Shared Function GetDataOfPoint(ByVal Latitude As Int32, ByVal
Longitude As Int32, ByRef Out As BMSDATA_SET) As Boolean
End Function



Die Deklaration der Funktion sollte richtig sein.

Ähnliche fragen