Valhalla Legends Forums Archive | .NET Platform | Converting C++ structs

AuthorMessageTime
Insolence
[code]struct GAMEINFO
{
DWORD _1[6]; //0x00
WORD _1a; //0x18
CHAR szGameName[0x18]; //0x1A
CHAR szGameServerIp[0x56]; //0x32
CHAR szAccountName[0x30]; //0x88
CHAR szCharName[0x18]; //0xB8
CHAR szRealmName[0x18]; //0xD0
BYTE _2[0x157]; //0xE8
CHAR szGamePassword[0x18]; //0x23F
};[/code]

This is what I have so far:
[code]    [StructLayout(LayoutKind.Explicit, CharSet = CharSet.Ansi)]
    public struct GameInfo
    {
        [FieldOffset(0x00)] [MarshalAs(UnmanagedType.ByValArray, SizeConst=6)]  public uint[] _1;
    [FieldOffset(0x18)] public UInt16  _1a;
        [FieldOffset(0x1A)] [MarshalAs(UnmanagedType.ByValTStr, SizeConst=24)] public string szGameName;
    [FieldOffset(0x32)] [MarshalAs(UnmanagedType.ByValTStr, SizeConst=86)] public string szGameServerIp;
    [FieldOffset(0x88)] [MarshalAs(UnmanagedType.ByValTStr, SizeConst=48)] public string szAccountName;
    [FieldOffset(0xB8)] [MarshalAs(UnmanagedType.ByValTStr, SizeConst=24)] public string szCharName;
    [FieldOffset(0xD0)] [MarshalAs(UnmanagedType.ByValTStr, SizeConst=24)] public string szRealmName;
    [FieldOffset(0xE8)] [MarshalAs(UnmanagedType.ByValArray, SizeConst=343)]  public uint[] _2;
    [FieldOffset(0x23F)] [MarshalAs(UnmanagedType.ByValTStr, SizeConst=24)] public string szGamePassword;
    }[/code]

EDIT:
Changing it to sequential did the trick.
July 15, 2007, 1:38 AM
Myndfyr
Why are you using ByValTStr?
July 15, 2007, 10:33 AM
Insolence
Should I not be?

It's working.
July 17, 2007, 5:20 AM

Search