Im having very tough challenge in converting the following code C#, can anybody help me on how do we do that.
typedef struct ACSNameAddr_t {
char FAR *serverName; // How do i use FAR in C#
struct {
short length;
unsigned char FAR *value;
} serverAddr;
} ACSNameAddr_t;
and how do i use this union in C#
typedef struct
{
union
{
CSTARouteRegisterAbortEvent_t registerAbort;
CSTARouteUsedEvent_t routeUsed;
CSTARouteUsedExtEvent_t routeUsedExt;
CSTARouteEndEvent_t routeEnd;
CSTAPrivateEvent_t privateEvent;
CSTASysStatEvent_t sysStat;
CSTASysStatEndedEvent_t sysStatEnded;
}u;
} CSTAEventReport;
Edit Answer:
So including all your answers, here by i’m writing the converted code. Please edit it if there is anything wrong, it might be useful for someone..
[StructLayout(LayoutKind.Sequential, Pack = 4)]
public struct ACSNameAddr_t
{
string serverName;
[StructLayout(LayoutKind.Sequential, Pack = 4)]
public struct serverAddr
{
public short length;
string value;
};
};
and for the second one,
[StructLayout(LayoutKind.Explicit, Pack = 4)]
public struct CSTAEventReport{
[StructLayout(LayoutKind.Explicit, Pack = 4)]
public struct u{
[FieldOffset(0)]
public CSTARouteRegisterAbortEvent_t registerAbort;
[FieldOffset(0)]
public CSTARouteUsedEvent_t routeUsed;
[FieldOffset(0)]
public CSTARouteUsedExtEvent_t routeUsedExt;
[FieldOffset(0)]
public CSTARouteEndEvent_t routeEnd;
[FieldOffset(0)]
public CSTAPrivateEvent_t privateEvent;
[FieldOffset(0)]
public CSTASysStatEvent_t sysStat;
[FieldOffset(0)]
public CSTASysStatEndedEvent_t sysStatEnded;
};
};
So including all your answers, here by i’m writing the converted code. Please edit it if there is anything wrong, it might be useful for someone..
and for the second one,