Why does MAKEINTRESOURCE() work?(为什么 MAKEINTRESOURCE() 有效?)
问题描述
宏定义为:
#define MAKEINTRESOURCEA(i) ((LPSTR)((ULONG_PTR)((WORD)(i))))
#define MAKEINTRESOURCEW(i) ((LPWSTR)((ULONG_PTR)((WORD)(i))))
为什么这可以用来指示资源 ID(16 位无符号整数)或其名称(指向字符数组的指针)?这不是有效地将地址空间(在 32 位系统上)限制为 16 位吗?否则系统怎么知道我用的是ID还是名字?
How come this can be used to indicate either a resource ID (a 16-bit unsigned int) or its name (a pointer to an array of char)? Doesn't this effectively limit the address space (on a 32-bit system) to 16-bit? Otherwise how does the system know whether I'm using an ID or a name?
推荐答案
这是可行的,因为 Windows 不允许为地址空间的前 64 KB 映射页面.捕获空指针引用.但我认为还要捕捉从 16 位版本的 Windows 转换而来的程序中的指针错误.
This works because Windows doesn't allow mapping pages for the first 64 KB of the address space. To catch null pointer references. But I think also to catch pointer bugs in programs that were converted from the 16-bit version of Windows.
一个副作用是,这允许可靠地区分打包成指针值的资源 ID,因为它们总是指向不可映射的内存.
A side-effect is that this allows to reliably distinguish resource IDs packed into a pointer value since they'll always point to non-mappable memory.
这篇关于为什么 MAKEINTRESOURCE() 有效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:为什么 MAKEINTRESOURCE() 有效?


- C++ 协变模板 2021-01-01
- 近似搜索的工作原理 2021-01-01
- 从python回调到c++的选项 2022-11-16
- 静态初始化顺序失败 2022-01-01
- 使用/clr 时出现 LNK2022 错误 2022-01-01
- 一起使用 MPI 和 OpenCV 时出现分段错误 2022-01-01
- Stroustrup 的 Simple_window.h 2022-01-01
- 与 int by int 相比,为什么执行 float by float 矩阵乘法更快? 2021-01-01
- STL 中有 dereference_iterator 吗? 2022-01-01
- 如何对自定义类的向量使用std::find()? 2022-11-07