Get file size in windows

I found this GetFileSizeEx () function, which returns the file size in PLARGE_INTEGER, which is formed by the union of structures.

typedef union _LARGE_INTEGER { struct { DWORD LowPart; LONG HighPart; } ; struct { DWORD LowPart; LONG HighPart; } u; LONGLONG QuadPart; } LARGE_INTEGER, *PLARGE_INTEGER; 

Is it as if I called it a structure of structures? How can I determine the size of the file that he returned, and how much information can be processed?

+6
source share
2 answers

You probably don't understand what union . File length is obtained

 LARGE_INTEGER len_li; GetFileSizeEx (hFile, &len_li); int64 len = (len_li.u.HighPart << 32) | len_li.u.LowPart; 

In addition, you can access the 64-bit representation directly using modern compilers:

 LARGE_INTEGER len_li; GetFileSizeEx (hFile, &len_li); LONGLONG len_ll = len_li.QuadPart; 
+4
source

no union is not a structure of structures.

I suggest you read this question and answer: The difference between structure and union in C

hope this helps clarify :)

+1
source

Source: https://habr.com/ru/post/896093/


All Articles