简体   繁体   中英

Get size of file in windows

I have found this function GetFileSizeEx() , which returns the size of file in PLARGE_INTEGER that 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 same as if I'd call it structure of structures? How can I figure the file size that it has returned and how large information can it handle?

You are probably misunderstanding what a union is. A file's length is obtained by

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

Alternatively, you can access the 64 bit representation directly with modern compilers:

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

no a union is NOT a struct of structs.

I suggest you read this question and answers: Difference between a Structure and a Union in C

hope this helps to clarify :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM