开发者

Get size of file in windows

开发者 https://www.devze.com 2023-04-01 12:21 出处:网络
I have found this function GetFileSizeEx(), which returns the size of file in PLARGE_INTEGER that is formed by the union of structures.

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 structu开发者_运维百科res? 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 :)

0

精彩评论

暂无评论...
验证码 换一张
取 消