Hello,
I am writing an app to read in an old file structure. It C++ this is how the code looks. I am trying to rewrite it in C# and can’t find any that will do it the same way. Here is how it should work.

// This is to just explain the structure.

#define	DRAWING_HEADER_FILL 888 
 
typedef struct DrbDwgHdr {		
	long	id;
	long	Vcount;
	char	desc[122];
	char	version[6];
	char	fill[DRAWING_HEADER_FILL];
	} DRB_DWG_HDR;

typedef	struct Atrb { unsigned	pen:6, ltyp:4, sel:1, other:2, dsp:1, beg:1, del:1; } ATRIB;

typedef struct DRBVec	{
	float			x_beg;
	float			y_beg;
	float			z_beg;
	float			x_end;
	float			y_end;
	float			z_end;
	ATRIB			attrib;
	unsigned			link;
	} DRBVEC;


class CDrawingsDoc : public CDocument
{

protected: // create from serialization only
	CDrawingsDoc();
	DECLARE_DYNCREATE(CDrawingsDoc)

// Attributes

public:
std::vector<DRBVEC> DrawingVec;
long DrawingVecCount;
int Scale, lx_org, ly_org;

UINT			m_QtyRead;
DRB_DWG_HDR		DRBDwgHdr;
DRBVEC			dvec;
int			size;

size=sizeof(DRBVEC);

// This is the part of the Code I can’t find something compatible
// in c#

CFile f(lpszPathName, CFile::modeRead);
	m_QtyRead=f.Read(&DRBDwgHdr, sizeof(DRBDwgHdr));
DrawingVec.clear();

for(long x = 0; x < DRBDwgHdr.Vcount ; x++)
	{
	m_QtyRead=f.Read(&dvec, size);
	DrawingVec.push_back(dvec);
	}

How do I read in a certain number of bytes directly into an object defined by a structure that contains floats and ints?
Thanks,
Todd

i like your thread's title :)

Yeah, but can you answer my question? ;)

#define	DRAWING_HEADER_FILL 888 
 
typedef struct DrbDwgHdr {		
	long	id;
	long	Vcount;
	char	desc[122];
	char	version[6];
	char	fill[DRAWING_HEADER_FILL];
	} DRB_DWG_HDR;

As a start I wold translate this to:

const int DRAWING_HEADER_FILL = 888;
 
struct DrbDwgHdr 
{		
	public long	id;
	public long	Vcount;
	char[]	desc = new char[122];
	char[]	version = new char[6];
	char[]	fill = new char[DRAWING_HEADER_FILL];
};
#define	DRAWING_HEADER_FILL 888 
 
typedef struct DrbDwgHdr {		
	long	id;
	long	Vcount;
	char	desc[122];
	char	version[6];
	char	fill[DRAWING_HEADER_FILL];
	} DRB_DWG_HDR;

As a start I wold translate this to:

const int DRAWING_HEADER_FILL = 888;
 
struct DrbDwgHdr 
{		
	public long	id;
	public long	Vcount;
	char[]	desc = new char[122];
	char[]	version = new char[6];
	char[]	fill = new char[DRAWING_HEADER_FILL];
};

Thank you for your help. I am working with an old file format and I have to be able to import old drawing files. The DrbDwgHdr Struct is the beginning header of a drawing file. I want to take the length of Struct and grab the matching length of the beginning of thr file on disk and put it in the object created from the struct. I can do it this way in C++

CFile f(lpszPathName, CFile::modeRead);
	m_QtyRead=f.Read(&DRBDwgHdr, sizeof(DRBDwgHdr));

Is there an easy way to do this in C#?

Thanks again for your help. I have been continuing to search the web for information and it looks like there is not an easy way to do his,

I would translate
CFile f(lpszPathName, CFile::modeRead);
m_QtyRead=f.Read(&DRBDwgHdr, sizeof(DRBDwgHdr));
to
FileStream fs = File.OpenRead(lpszPathName);
m_QtyRead = fs.Read(DRBDwgHdr, 0, DRBDwgHdr.Length);

This question has already been answered. Start a new discussion instead.