Good day to all, please help determine the size of the structure in C #, there is a certain structure in C ++:
typedef struct { short int n; unsigned long adr; int nz,ms; TDateTime tr; TDateTime tz; TDateTime tv; TDateTime ts; short tm,sk,dop; float bz,hz,hzz,hdm,hdp,h0,h1; float l,ldm,ldp,lbm,lbp; float pf,pt,pdm,pdp,pbm,pbp,pu,pe; float l_1,l_2,l_3,l_4; float h1s,h2s,h3s,h4si,h1si; float t1s,t2s,t3s,t4s; float d1,d2,d3,d4; float gh4n,gh4z,gh4s,gh1z,gh1s; float l4; float d_rr,d_rv; int k_t,k_z; float f_rez[4]; int i_rez[4]; } ser; And another one :
typedef struct { TDateTime dt; short int Nbr,Nsm,Nr; float pt,pf,pdm,pdp; float pbm,pbp,pu,pe; float ps[12]; float ph[8]; float phu[8]; //int prs,pr[8]; int prs; short pr[8],kr[8]; unsigned int m[16]; unsigned int s[16]; float frez[4]; int irez[4]; } str_sm; Next, in C ++, the sizes of these structures are determined:
fser=CreateFile(AnsiString(S).c_str(),GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL); if (fser!=INVALID_HANDLE_VALUE) { long int ss=sizeof(str_sm)+((nrs.n.nr-1)*(sizeof(ser))); SetFilePointer(fser,ss,NULL,FILE_BEGIN); ReadFile(fser,&sr,sizeof(ser),&lread,NULL); CloseHandle(fser); flag=true; } How can I also find out the size of the structure? to make a shift in a binary file, I try this:
struct test { int n; ulong adr; int nz, ms; double tr; double tz; double tv; double ts; short tm, sk, dop; float bz, hz, hzz, hdm, hdp, h0, h1; float l, ldm, ldp, lbm, lbp; float pf, pt, pdm, pdp, pbm, pbp, pu, pe; float l_1, l_2, l_3, l_4; float h1s, h2s, h3s, h4si, h1si; float t1s, t2s, t3s, t4s; float d1, d2, d3, d4; float gh4n, gh4z, gh4s, gh1z, gh1s; float l4; float d_rr, d_rv; int k_t, k_z; float[] f_redz1; float[] f_redz2; float[] f_redz3; float[] f_redz4; float[] f_redz5; int[] i_rez1; int[] i_rez2; int[] i_rez3; int[] i_rez4; int[] i_rez5; } test te = new test(); int abcd = System.Runtime.InteropServices.Marshal.SizeOf(typeof(test)); at the output I get 296 ... I did the same with the second structure and with this solution abcd + 0 * abcd2 = 296 (But I started the C ++ debugger and there = 360). Please help me understand, thank you very much.