Skip to content
TopicTracker
来自 devblogs.microsoft.com/oldnewthing查看原文
译文语言译文语言

Windows中窗口和类额外字节的演变

本文探讨了Windows中窗口额外字节(Window Extra Bytes)和类额外字节(Class Extra Bytes)的设计演变。前缀编码了这些数据的预期用途,帮助开发者理解和管理窗口与类结构中的自定义存储空间。

背景速读

- Raymond Chen 是微软资深工程师,自 2003 年起撰写《The Old New Thing》博客,专门解释 Windows 内部机制和历史设计决策,深受开发者社区信赖。 - Windows 中的「窗口额外字节」(window extra bytes)和「类额外字节」(class extra bytes)是一项从 16 位 Windows 时代延续至今的底层机制,允许开发者在窗口对象或窗口类结构中预留一小块自定义内存,用于存储与窗口相关的私有数据。 - 在早期 Windows(如 Windows 3.x)中,内存极其有限且没有可靠的数据封装手段,这一机制是开发者附加数据到窗口上的主要方式,后来逐渐被 SetProp/GetProp、窗口子类化(subclassing)以及 32 位下的 GWL_USERDATA 等更灵活的方案替代。 - 这篇短文是系列中的一篇,通过前面帖子的前缀编码惯例(如后缀字母代表用法)来讨论这些额外字节在 Windows 演进中的角色变化,帮助理解 Windows API 中的兼容性债与设计演变。

相关报道

  • A developer found that a DLL was no longer in memory even though it hadn't been formally unloaded, tracing the issue to Windows' DLL load ordering. When a DLL is loaded at a base address that conflicts with another DLL loaded earlier, the system may relocate it and then later discard the relocated version without clear notification, confusing developers expecting explicit unload.