windows下获取文件大小

发布于 2024-12-01 17:39:38 字数 440 浏览 1 评论 0原文

我找到了这个函数 GetFileSizeEx(),它返回由结构体并集形成的 PLARGE_INTEGER 格式的文件大小。

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

这和我称之为结构的结构一样吗?如何计算它返回的文件大小以及它可以处理多大的信息?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

衣神在巴黎 2024-12-08 17:39:38

您可能误解了union是什么。文件的长度可以通过以下方式获取

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

:或者,您可以使用现代编译器直接访问 64 位表示形式:

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

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;
趁微风不噪 2024-12-08 17:39:38

不,联合不是结构的结构。

我建议您阅读这个问题和答案:结构和结构之间的区别C 中的 Union

希望这有助于澄清:)

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 :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文