Autor Beitrag
KokaLola
Hält's aus hier
Beiträge: 12



BeitragVerfasst: Sa 30.10.10 00:58 
Moin - ich habe ein problem unzwar möchte ich dieses Stuct union (c++) in c# convertieren nur versteh ich es iwie doch nicht...

C++-Code:
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
********************************************
union MyType{
  int   i_Param;
  float   f_Param;
  DWORD  d_Param;
  //wchar_t wc_Param[50];
};

struct S_Header{
  unsigned short header;
  unsigned short type;
  MyType LParam,MParam,RParam,
    returnValue1,
    returnValue2;
};
********************************************


Mein Versuch in c#:
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
********************************************
        public struct S_Header
        {
            [FieldOffset(0)]
            public ushort header;
            [FieldOffset(2)]
            public ushort type;
            [FieldOffset(8)]
            public int i_LParam;
            [FieldOffset(8)]
            public float f_LParam;
            [FieldOffset(12)]
            public int i_MParam;
            [FieldOffset(12)]
            public float f_MParam;
            [FieldOffset(16)]
            public int i_RParam;
            [FieldOffset(16)]
            public float f_RParam;
            [FieldOffset(20)]
            public int i_returnValue1;
            [FieldOffset(20)]
            public float f_returnValue1;
            [FieldOffset(24)]
            public int i_returnValue2;
            [FieldOffset(24)]
            public float f_returnValue2;
        }
********************************************



Vielleicht weiß ja jmd. was ich falsch gemacht habe.....


Mit freundlichen Grüßen

Moderiert von user profile iconKha: C#-Tags hinzugefügt
Greenberet
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 339
Erhaltene Danke: 20

Win 10
C# (VS 2012), C++ (VS 2012/GCC), PAWN(Notepad++), Java(NetBeans)
BeitragVerfasst: Sa 30.10.10 19:11 
Probiers mal mit

ausblenden C#-Quelltext
1:
2:
3:
4:
[StructLayout(LayoutKind.Explicit)]
public struct S_Header
{
//...
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19341
Erhaltene Danke: 1752

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Sa 30.10.10 19:16 
Außerdem kannst du nicht zwei gleiche Offsets angeben. Wie sollen zwei Informationen an der physikalisch gleichen Stelle stehen? :shock:
Kha
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3803
Erhaltene Danke: 176

Arch Linux
Python, C, C++ (vim)
BeitragVerfasst: Sa 30.10.10 19:47 
user profile iconjaenicke hat folgendes geschrieben Zum zitierten Posting springen:
Außerdem kannst du nicht zwei gleiche Offsets angeben.
Äh, das ist doch der ganze Witz an LayoutKind.Explicit ;) ...

_________________
>λ=
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19341
Erhaltene Danke: 1752

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Sa 30.10.10 19:50 
Ja, jetzt seh ichs auch wie der ursprüngliche Quelltext in C++ gemeint ist. :oops: