Laden...

Unions mit Structs in C#

Erstellt von Gugi vor 16 Jahren Letzter Beitrag vor 16 Jahren 1.685 Views
G
Gugi Themenstarter:in
1 Beiträge seit 2007
vor 16 Jahren
Unions mit Structs in C#

Hallo!

Habe ein großes Problem! Ich möchte den folgenden C++ Code in C# nachbauen!
Das Problem ist dass die Union ganz oben Structs enthält die ihrerseits wieder Structs
enthalten die dann alle unterschiedliche Längen haben.
Ich hätte das ganze auch schon so probiert wie man es nachbilden sollte nämlich mit
FieldOffset ... haut aber überhaupt nicht hin. Problem: Alle Beispiele mit Unions die ich gefunden habe, verwenden einfache Datentypen .... aber keine Structs 😉

gleich darunter ist mein Versuch ... geht aber nicht wirklich *g

Hat irgenwer von euch eine Ahnung wie man so was macht???

mfg Stefan!


[StructLayout(LayoutKind.Explicit)]
        public struct phHal_uRemoteDevInfo
        {
            [FieldOffset(0)]
            phHal_sPassive106MfCardInformation CardInfo106;
            
            [FieldOffset(0)]
            phHal_sPassive106NfcInformation NfcInfo106;
            
            [FieldOffset(0)]
            phHal_sPassive212_424CardInformation CardInfo212_424;
            
            [FieldOffset(0)]
            phHal_sPassive212_424NfcInformation NfcInfo212_424;
            
            [FieldOffset(0)]
            phHal_sNfcActiveInformation NfcActiveInfo;
            
            [FieldOffset(0)]
            phHal_sPassive106_ISO14443_4A_CardInformation ISO14443_4A_Info;
        }



typedef union phHal_uRemoteDevInfo
 {
   phHal_sPassive106MfCardInformation_t             CardInfo106;        
   phHal_sPassive106NfcInformation_t                NfcInfo106;         
   phHal_sPassive212_424CardInformation_t           CardInfo212_424;    
   phHal_sPassive212_424NfcInformation_t            NfcInfo212_424;     
   phHal_sNfcActiveInformation_t                    NfcActiveInfo;      
   phHal_sPassive106_ISO14443_4A_CardInformation_t  ISO14443_4A_Info;   
 } phHal_uRemoteDevInfo_t;
 
 
 typedef struct phHal_sRemoteDevInformation
 {
     uint8_t                    hLogHandle;          
     uint8_t                    SessionOpened;       
     phHal_eOpModes_t           OpMode;              
     phHal_uRemoteDevInfo_t     RemoteDevInfo;       
     /* Mantis 181 */
     uint8_t UsedDID;                                
     uint8_t UsedNAD;                                
} phHal_sRemoteDevInformation_t;


typedef struct phHal_sPassive106Startup
 {
     uint8_t             SensRes[2];         
     uint8_t             SelRes;             
     uint8_t             NFCID1tLength;      
     uint8_t             NFCID1t[PHHAL_NFCID_LENGTH];     
 } phHal_sPassive106Startup_t;
 
 
 typedef struct phHal_sPassive212_424Startup
 {
     uint8_t             RespCode;            
     uint8_t             NFCID2t[8];          
     uint8_t             PMm[8];              
     uint8_t             SystemCodeAvailable; 
     uint8_t             SystemCode[2];       
} phHal_sPassive212_424Startup_t;
 
 
 typedef struct phHal_sNfcProtocol
 {
     uint8_t NFCID3t[PHHAL_NFCID_LENGTH];        
     uint8_t TgGeneralByte[48];  
     uint8_t TgGeneralByteLength;
     uint8_t DIDtUsed;           
     uint8_t NADtSup;            
 } phHal_NfcProtocol_t;
 
 
 typedef struct phHal_sISO_14443_4_Protocol
 {
     uint8_t HistoBytes[256];  
     uint8_t HistoBytesLength; 
     uint8_t CIDUsed;          
     uint8_t NADUsed;          
 } phHal_sISO_14443_4_Protocol_t;
 
 
 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
 
 
 typedef struct phHal_sPassive106MfCardInformation
 {
    phHal_eStateList_t         CurrentState;  
    phHal_sPassive106Startup_t Startup106;    
 } phHal_sPassive106MfCardInformation_t;
 
 
 typedef struct phHal_sPassive106_ISO14443_4A_CardInformation
 {
     phHal_eStateList_t            CurrentState;         
     phHal_sPassive106Startup_t    Startup106;           
     phHal_sISO_14443_4_Protocol_t ISO14443_4A_Protocol; 
} phHal_sPassive106_ISO14443_4A_CardInformation_t;
 
 
 typedef struct phHal_sPassive106NfcInformation
 {
     phHal_eStateList_t         CurrentState;
    phHal_sPassive106Startup_t Startup106;  
    phHal_NfcProtocol_t        NfcProtocol; 
 }phHal_sPassive106NfcInformation_t;
 
 
 typedef struct phHal_sPassive212_424CardInformation
 {
     phHal_eStateList_t              CurrentState;    
     phHal_sPassive212_424Startup_t  Startup212_424;  
 } phHal_sPassive212_424CardInformation_t;
 
 
 typedef struct phHal_sPassive212_424NfcInformation
 {
     phHal_eStateList_t              CurrentState;    
     phHal_sPassive212_424Startup_t  Startup212_424;  
     phHal_NfcProtocol_t             NfcProtocol;     
 } phHal_sPassive212_424NfcInformation_t;
 
 
 typedef struct phHal_sNfcActiveInformation
 {
     phHal_eStateList_t   CurrentState;  
     phHal_NfcProtocol_t  NfcProtocol;   
} phHal_sNfcActiveInformation_t;

B
1.529 Beiträge seit 2006
vor 16 Jahren

Wenn du alle structs jeweils mit LayoutKind.Explicit definierst, sollte es eigentlich gehen.