char of specific lengt in struct?

J

jodleren

Hi all

The documentation says:
typedef struct {
unsigned char name[4]; /* four-character file name */
unsigned char extension; /* extension number, range 0 - 99, 127
*/
unsigned char startpage; /* page number where file starts */
unsigned char numpages; /* number of pages occupied by file */
unsigned char attrib; /* file/directory attribute */
unsigned char bitmap[32]; /* current bitmap of the device */
} FileEntry;

[ http://files.dalsemi.com/auto_id/softdev/owdocs_400beta2/Docs/TMEX/file30mx.html
for
http://files.dalsemi.com/auto_id/softdev/owdocs_400beta2/Docs/TMEX/crfi4x7y.html
]

I tried:

struct TFileEntry
{
public char[] name = new char[4]; /* four-character
file name */
public char extension; /* extension
number, range 0 - 99, 127 */
public char startpage; /* page number
where file starts */
public char numpages; /* number of pages
occupied by file */
public char attrib; /* file/directory
attribute */
public char[] bitmap = new char[32]; /* current bitmap
of the device */
}

What is the right solution to this?

WBR
Sonnich
 
A

Arne Vajhøj

The documentation says:
typedef struct {
unsigned char name[4]; /* four-character file name */
unsigned char extension; /* extension number, range 0 - 99, 127
*/
unsigned char startpage; /* page number where file starts */
unsigned char numpages; /* number of pages occupied by file */
unsigned char attrib; /* file/directory attribute */
unsigned char bitmap[32]; /* current bitmap of the device */
} FileEntry;

[ http://files.dalsemi.com/auto_id/softdev/owdocs_400beta2/Docs/TMEX/file30mx.html
for
http://files.dalsemi.com/auto_id/softdev/owdocs_400beta2/Docs/TMEX/crfi4x7y.html
]

I tried:

struct TFileEntry
{
public char[] name = new char[4]; /* four-character
file name */
public char extension; /* extension
number, range 0 - 99, 127 */
public char startpage; /* page number
where file starts */
public char numpages; /* number of pages
occupied by file */
public char attrib; /* file/directory
attribute */
public char[] bitmap = new char[32]; /* current bitmap
of the device */
}

What is the right solution to this?

Try:

char s[10];

->

[MarshalAs(UnmanagedType.ByValTStr,SizeConst=10)]
public string s;

Arne
 
J

jodleren

The documentation says:
typedef struct {
    unsigned char name[4];       /* four-character file name */
    unsigned char extension;     /* extension number, range 0 -99, 127
*/
    unsigned char startpage;     /* page number where file starts */
    unsigned char numpages;      /* number of pages occupied by file */
    unsigned char attrib;        /* file/directory attribute */
    unsigned char bitmap[32];    /* current bitmap of the device */
} FileEntry;

I tried:
struct TFileEntry
         {
            public char[] name = new char[4];       /* four-character
file name */
            public char extension;                   /* extension
number, range 0 - 99, 127 */
            public char startpage;                   /* page number
where file starts */
            public char numpages;                    /* number of pages
occupied by file */
            public char attrib;                     /* file/directory
attribute */
            public char[] bitmap = new char[32];     /* current bitmap
of the device */
         }
What is the right solution to this?

Try:

char s[10];

- ssy>

         [MarshalAs(UnmanagedType.ByValTStr,SizeConst=10)]
         public string s;

Arne

I did not work - my system is old ASCII bases, so I created a class,
which puts it all in an byte[] array
It works

sonnich
 
A

Arne Vajhøj

Try:

char s[10];

- ssy>

[MarshalAs(UnmanagedType.ByValTStr,SizeConst=10)]
public string s;

I did not work - my system is old ASCII bases, so I created a class,
which puts it all in an byte[] array
It works

With:

[StructLayout(LayoutKind.Sequential,CharSet=CharSet.Ansi,Pack=1)]

on the struct then the suggested should work perfectly with
ASCII (ANSI is a superset of ASCII).

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top